using System;
namespace MicroMsg.Common.Audio.Amr
{
	public class GloabFunc_Dec
	{
		public enum DTXStateType
		{
			SPEECH,
			DTX,
			DTX_MUTE
		}
		public class Bgn_scdState
		{
			public int[] frameEnergyHist;
			public short bgHangover;
			public Bgn_scdState()
			{
				this.frameEnergyHist = new int[60];
				this.bgHangover = 0;
			}
		}
		public class Cb_gain_averageState
		{
			public int hangCount;
			public int[] cbGainHistory;
			public short hangVar;
			public Cb_gain_averageState()
			{
				this.hangCount = 0;
				this.cbGainHistory = new int[7];
				this.hangVar = 0;
			}
		}
		public class lsp_avgState
		{
			public int[] lsp_meanSave;
			public lsp_avgState()
			{
				this.lsp_meanSave = new int[10];
			}
		}
		public class D_plsfState
		{
			public int[] past_r_q;
			public int[] past_lsf_q;
			public D_plsfState()
			{
				this.past_r_q = new int[10];
				this.past_lsf_q = new int[10];
			}
		}
		public class ec_gain_pitchState
		{
			public int[] pbuf;
			public int past_gain_pit;
			public int prev_gp;
			public ec_gain_pitchState()
			{
				this.pbuf = new int[5];
				this.past_gain_pit = 0;
				this.prev_gp = 0;
			}
		}
		public class ec_gain_codeState
		{
			public int[] gbuf;
			public int past_gain_code;
			public int prev_gc;
			public ec_gain_codeState()
			{
				this.gbuf = new int[5];
				this.past_gain_code = 0;
				this.prev_gc = 0;
			}
		}
		public class gc_predState
		{
			public int[] past_qua_en;
			public int[] past_qua_en_MR122;
			public gc_predState()
			{
				this.past_qua_en = new int[4];
				this.past_qua_en_MR122 = new int[4];
			}
		}
		public class ph_dispState
		{
			public int[] gainMem;
			public int prevCbGain;
			public int prevState;
			public int lockFull;
			public int onset;
			public ph_dispState()
			{
				this.gainMem = new int[5];
				this.prevCbGain = 0;
				this.prevState = 0;
				this.lockFull = 0;
				this.onset = 0;
			}
		}
		public class dtx_decState
		{
			public GloabFunc_Dec.DTXStateType dtxGlobalState;
			public int log_en;
			public int old_log_en;
			public int pn_seed_rx;
			public int[] int_0;
			public int[] lsp_old;
			public int[] lsf_hist;
			public int[] lsf_hist_mean;
			public int[] log_en_hist;
			public int true_sid_period_inv;
			public short since_last_sid;
			public short lsf_hist_ptr;
			public short log_pg_mean;
			public short log_en_hist_ptr;
			public short log_en_adjust;
			public short dtxHangoverCount;
			public short decAnaElapsedCount;
			public short sid_frame;
			public short valid_data;
			public short dtxHangoverAdded;
			public short data_updated;
			public dtx_decState()
			{
				this.dtxGlobalState = GloabFunc_Dec.DTXStateType.DTX;
				this.log_en = 0;
				this.pn_seed_rx = 0;
				this.int_0 = new int[10];
				this.lsp_old = new int[10];
				this.lsf_hist = new int[80];
				this.lsf_hist_mean = new int[80];
				this.log_en_hist = new int[8];
				this.true_sid_period_inv = 0;
				this.since_last_sid = 0;
				this.lsf_hist_ptr = 0;
				this.log_pg_mean = 0;
				this.log_en_hist_ptr = 0;
				this.log_en_adjust = 0;
				this.dtxHangoverCount = 0;
				this.decAnaElapsedCount = 0;
				this.sid_frame = 0;
				this.valid_data = 0;
				this.dtxHangoverAdded = 0;
				this.data_updated = 0;
			}
		}
		public class agcState
		{
			public int past_gain;
			public agcState()
			{
				this.past_gain = 0;
			}
		}
		public class Decoder_amrState
		{
			public int[] old_exc;
			public int old_excOffset;
			public int[] int_0;
			public int excOffset;
			public int[] lsp_old;
			public int[] mem_syn;
			public int mem_synOffset;
			public int sharp;
			public int old_T0;
			public int T0_lagBuff;
			public int inBackgroundNoise;
			public int voicedHangover;
			public int[] ltpGainHistory;
			public int ltpGainHistoryOffset;
			public int[] excEnergyHist;
			public int excEnergyHistOffset;
			public short prev_bf;
			public short prev_pdf;
			public short state;
			public short nodataSeed;
			public GloabFunc_Dec.Bgn_scdState background_state;
			public GloabFunc_Dec.Cb_gain_averageState Cb_gain_averState;
			public GloabFunc_Dec.lsp_avgState lsp_avg_st;
			public GloabFunc_Dec.D_plsfState lsfState;
			public GloabFunc_Dec.ec_gain_pitchState ec_gain_p_st;
			public GloabFunc_Dec.ec_gain_codeState ec_gain_c_st;
			public GloabFunc_Dec.gc_predState pred_state;
			public GloabFunc_Dec.ph_dispState ph_disp_st;
			public GloabFunc_Dec.dtx_decState dtxDecoderState;
			public Decoder_amrState()
			{
				this.old_exc = new int[194];
				this.old_excOffset = 0;
				this.lsp_old = new int[10];
				this.mem_syn = new int[10];
				this.sharp = 0;
				this.old_T0 = 0;
				this.T0_lagBuff = 0;
				this.inBackgroundNoise = 0;
				this.voicedHangover = 0;
				this.ltpGainHistory = new int[9];
				this.excEnergyHist = new int[9];
				this.prev_bf = 0;
				this.prev_pdf = 0;
				this.state = 0;
				this.nodataSeed = 0;
				this.background_state = null;
				this.Cb_gain_averState = null;
				this.lsp_avg_st = null;
				this.lsfState = null;
				this.ec_gain_p_st = null;
				this.ec_gain_c_st = null;
				this.pred_state = null;
				this.ph_disp_st = null;
				this.dtxDecoderState = null;
			}
		}
		public class Post_FilterState
		{
			public int[] res2;
			public int[] mem_syn_pst;
			public int[] synth_buf;
			public int preemph_state_mem_pre;
			public GloabFunc_Dec.agcState agc_state;
			public Post_FilterState()
			{
				this.res2 = new int[40];
				this.mem_syn_pst = new int[10];
				this.synth_buf = new int[170];
				this.preemph_state_mem_pre = 0;
			}
		}
		public class Post_ProcessState
		{
			public int y2_hi;
			public int y2_lo;
			public int y1_hi;
			public int y1_lo;
			public int int_0;
			public int int_1;
			public Post_ProcessState()
			{
				this.y2_hi = 0;
				this.y2_lo = 0;
				this.y1_hi = 0;
				this.y1_lo = 0;
				this.int_0 = 0;
				this.int_1 = 0;
			}
		}
		public class Speech_Decode_FrameState
		{
			public GloabFunc_Dec.Decoder_amrState decoder_amrState;
			public GloabFunc_Dec.Post_FilterState post_state;
			public GloabFunc_Dec.Post_ProcessState postHP_state;
			public Speech_Decode_FrameState()
			{
				this.decoder_amrState = null;
				this.post_state = null;
				this.postHP_state = null;
			}
		}
		public static short[] bitno_MR475 = new short[]
		{
			8,
			8,
			7,
			8,
			7,
			2,
			8,
			4,
			7,
			2,
			4,
			7,
			2,
			8,
			4,
			7,
			2
		};
		public static short[] bitno_MR515 = new short[]
		{
			8,
			8,
			7,
			8,
			7,
			2,
			6,
			4,
			7,
			2,
			6,
			4,
			7,
			2,
			6,
			4,
			7,
			2,
			6
		};
		public static short[] bitno_MR59 = new short[]
		{
			8,
			9,
			9,
			8,
			9,
			2,
			6,
			4,
			9,
			2,
			6,
			8,
			9,
			2,
			6,
			4,
			9,
			2,
			6
		};
		public static short[] bitno_MR67 = new short[]
		{
			8,
			9,
			9,
			8,
			11,
			3,
			7,
			4,
			11,
			3,
			7,
			8,
			11,
			3,
			7,
			4,
			11,
			3,
			7
		};
		public static short[] bitno_MR74 = new short[]
		{
			8,
			9,
			9,
			8,
			13,
			4,
			7,
			5,
			13,
			4,
			7,
			8,
			13,
			4,
			7,
			5,
			13,
			4,
			7
		};
		public static short[] bitno_MR795 = new short[]
		{
			9,
			9,
			9,
			8,
			13,
			4,
			4,
			5,
			6,
			13,
			4,
			4,
			5,
			8,
			13,
			4,
			4,
			5,
			6,
			13,
			4,
			4,
			5
		};
		public static short[] bitno_MR102 = new short[]
		{
			8,
			9,
			9,
			8,
			1,
			1,
			1,
			1,
			10,
			10,
			7,
			7,
			5,
			1,
			1,
			1,
			1,
			10,
			10,
			7,
			7,
			8,
			1,
			1,
			1,
			1,
			10,
			10,
			7,
			7,
			5,
			1,
			1,
			1,
			1,
			10,
			10,
			7,
			7
		};
		public static short[] bitno_MR122 = new short[]
		{
			7,
			8,
			9,
			8,
			6,
			9,
			4,
			4,
			4,
			4,
			4,
			4,
			3,
			3,
			3,
			3,
			3,
			5,
			6,
			4,
			4,
			4,
			4,
			4,
			4,
			3,
			3,
			3,
			3,
			3,
			5,
			9,
			4,
			4,
			4,
			4,
			4,
			4,
			3,
			3,
			3,
			3,
			3,
			5,
			6,
			4,
			4,
			4,
			4,
			4,
			4,
			3,
			3,
			3,
			3,
			3,
			5
		};
		public static short[] bitno_MRDTX = new short[]
		{
			3,
			8,
			9,
			9,
			6
		};
		private static void Decoder_amr_reset(GloabFunc_Dec.Decoder_amrState state, Mode mode)
		{
			GloabFunc.memsetInt(state.Cb_gain_averState.cbGainHistory, 0, 0, 28);
			state.Cb_gain_averState.hangVar = 0;
			state.Cb_gain_averState.hangCount = 0;
			state.int_0 = state.old_exc;
			state.excOffset = state.old_excOffset + 143 + 11;
			GloabFunc.memsetInt(state.old_exc, state.old_excOffset, 0, 616);
			if (mode != Mode.MRDTX)
			{
				GloabFunc.memsetInt(state.mem_syn, 0, 0, 40);
			}
			state.sharp = 0;
			state.old_T0 = 40;
			if (mode != Mode.MRDTX)
			{
				state.lsp_old[0] = 30000;
				state.lsp_old[1] = 26000;
				state.lsp_old[2] = 21000;
				state.lsp_old[3] = 15000;
				state.lsp_old[4] = 8000;
				state.lsp_old[5] = 0;
				state.lsp_old[6] = -8000;
				state.lsp_old[7] = -15000;
				state.lsp_old[8] = -21000;
				state.lsp_old[9] = -26000;
			}
			state.prev_bf = 0;
			state.prev_pdf = 0;
			state.state = 0;
			state.T0_lagBuff = 40;
			state.inBackgroundNoise = 0;
			state.voicedHangover = 0;
			if (mode != Mode.MRDTX)
			{
				GloabFunc.memsetInt(state.excEnergyHist, 0, 0, 36);
			}
			GloabFunc.memsetInt(state.ltpGainHistory, 0, 0, 36);
			if (mode != Mode.MRDTX)
			{
				state.lsp_avg_st.lsp_meanSave[0] = 1384;
				state.lsp_avg_st.lsp_meanSave[1] = 2077;
				state.lsp_avg_st.lsp_meanSave[2] = 3420;
				state.lsp_avg_st.lsp_meanSave[3] = 5108;
				state.lsp_avg_st.lsp_meanSave[4] = 6742;
				state.lsp_avg_st.lsp_meanSave[5] = 8122;
				state.lsp_avg_st.lsp_meanSave[6] = 9863;
				state.lsp_avg_st.lsp_meanSave[7] = 11092;
				state.lsp_avg_st.lsp_meanSave[8] = 12714;
				state.lsp_avg_st.lsp_meanSave[9] = 13701;
			}
			GloabFunc.memsetInt(state.lsfState.past_r_q, 0, 0, 40);
			state.lsfState.past_lsf_q[0] = 1384;
			state.lsfState.past_lsf_q[1] = 2077;
			state.lsfState.past_lsf_q[2] = 3420;
			state.lsfState.past_lsf_q[3] = 5108;
			state.lsfState.past_lsf_q[4] = 6742;
			state.lsfState.past_lsf_q[5] = 8122;
			state.lsfState.past_lsf_q[6] = 9863;
			state.lsfState.past_lsf_q[7] = 11092;
			state.lsfState.past_lsf_q[8] = 12714;
			state.lsfState.past_lsf_q[9] = 13701;
			for (int i = 0; i < 5; i++)
			{
				state.ec_gain_p_st.pbuf[i] = 1640;
			}
			state.ec_gain_p_st.past_gain_pit = 0;
			state.ec_gain_p_st.prev_gp = 16384;
			for (int i = 0; i < 5; i++)
			{
				state.ec_gain_c_st.gbuf[i] = 1;
			}
			state.ec_gain_c_st.past_gain_code = 0;
			state.ec_gain_c_st.prev_gc = 1;
			if (mode != Mode.MRDTX)
			{
				for (int i = 0; i < 4; i++)
				{
					state.pred_state.past_qua_en[i] = -14336;
					state.pred_state.past_qua_en_MR122[i] = -2381;
				}
			}
			state.nodataSeed = 21845;
			GloabFunc.memsetInt(state.background_state.frameEnergyHist, 0, 0, 240);
			state.background_state.bgHangover = 0;
			GloabFunc.memsetInt(state.ph_disp_st.gainMem, 0, 0, 20);
			state.ph_disp_st.prevState = 0;
			state.ph_disp_st.prevCbGain = 0;
			state.ph_disp_st.lockFull = 0;
			state.ph_disp_st.onset = 0;
			if (mode != Mode.MRDTX)
			{
				state.dtxDecoderState.since_last_sid = 0;
				state.dtxDecoderState.true_sid_period_inv = 8192;
				state.dtxDecoderState.log_en = 3500;
				state.dtxDecoderState.old_log_en = 3500;
				state.dtxDecoderState.pn_seed_rx = 1887529304;
				state.dtxDecoderState.int_0[0] = 30000;
				state.dtxDecoderState.int_0[1] = 26000;
				state.dtxDecoderState.int_0[2] = 21000;
				state.dtxDecoderState.int_0[3] = 15000;
				state.dtxDecoderState.int_0[4] = 8000;
				state.dtxDecoderState.int_0[5] = 0;
				state.dtxDecoderState.int_0[6] = -8000;
				state.dtxDecoderState.int_0[7] = -15000;
				state.dtxDecoderState.int_0[8] = -21000;
				state.dtxDecoderState.int_0[9] = -26000;
				state.dtxDecoderState.lsp_old[0] = 30000;
				state.dtxDecoderState.lsp_old[1] = 26000;
				state.dtxDecoderState.lsp_old[2] = 21000;
				state.dtxDecoderState.lsp_old[3] = 15000;
				state.dtxDecoderState.lsp_old[4] = 8000;
				state.dtxDecoderState.lsp_old[5] = 0;
				state.dtxDecoderState.lsp_old[6] = -8000;
				state.dtxDecoderState.lsp_old[7] = -15000;
				state.dtxDecoderState.lsp_old[8] = -21000;
				state.dtxDecoderState.lsp_old[9] = -26000;
				state.dtxDecoderState.lsf_hist_ptr = 0;
				state.dtxDecoderState.log_pg_mean = 0;
				state.dtxDecoderState.log_en_hist_ptr = 0;
				state.dtxDecoderState.lsf_hist[0] = 1384;
				state.dtxDecoderState.lsf_hist[1] = 2077;
				state.dtxDecoderState.lsf_hist[2] = 3420;
				state.dtxDecoderState.lsf_hist[3] = 5108;
				state.dtxDecoderState.lsf_hist[4] = 6742;
				state.dtxDecoderState.lsf_hist[5] = 8122;
				state.dtxDecoderState.lsf_hist[6] = 9863;
				state.dtxDecoderState.lsf_hist[7] = 11092;
				state.dtxDecoderState.lsf_hist[8] = 12714;
				state.dtxDecoderState.lsf_hist[9] = 13701;
				for (int i = 1; i < 8; i++)
				{
					GloabFunc.memcpyInt(state.dtxDecoderState.lsf_hist, 10 * i, state.dtxDecoderState.lsf_hist, 0, 10);
				}
				GloabFunc.memsetInt(state.dtxDecoderState.lsf_hist_mean, 0, 0, 320);
				for (int i = 0; i < 8; i++)
				{
					state.dtxDecoderState.log_en_hist[i] = state.dtxDecoderState.log_en;
				}
				state.dtxDecoderState.log_en_adjust = 0;
				state.dtxDecoderState.dtxHangoverCount = 7;
				state.dtxDecoderState.decAnaElapsedCount = 31;
				state.dtxDecoderState.sid_frame = 0;
				state.dtxDecoderState.valid_data = 0;
				state.dtxDecoderState.dtxHangoverAdded = 0;
				state.dtxDecoderState.dtxGlobalState = GloabFunc_Dec.DTXStateType.DTX;
				state.dtxDecoderState.data_updated = 0;
			}
		}
		private static GloabFunc_Dec.DTXStateType rx_dtx_handler(GloabFunc_Dec.dtx_decState dtx_decState_0, RXFrameType frame_type)
		{
			GloabFunc_Dec.DTXStateType dTXStateType;
			if (((GloabFunc_Dec.DTXStateType)DefineConstants_Dec.table_SID[(int)frame_type] | (dtx_decState_0.dtxGlobalState & (GloabFunc_Dec.DTXStateType)DefineConstants_Dec.table_speech_bad[(int)frame_type])) != GloabFunc_Dec.DTXStateType.SPEECH)
			{
				dTXStateType = GloabFunc_Dec.DTXStateType.DTX;
				if ((((dtx_decState_0.dtxGlobalState == GloabFunc_Dec.DTXStateType.DTX_MUTE) ? 1 : 0) & DefineConstants_Dec.table_mute[(int)frame_type]) != 0)
				{
					dTXStateType = GloabFunc_Dec.DTXStateType.DTX_MUTE;
				}
				dtx_decState_0.since_last_sid += 1;
				if (frame_type != RXFrameType.RX_SID_UPDATE & dtx_decState_0.since_last_sid > 50)
				{
					dTXStateType = GloabFunc_Dec.DTXStateType.DTX_MUTE;
				}
			}
			else
			{
				dTXStateType = GloabFunc_Dec.DTXStateType.SPEECH;
				dtx_decState_0.since_last_sid = 0;
			}
			if (dtx_decState_0.data_updated == 0 & frame_type == RXFrameType.RX_SID_UPDATE)
			{
				dtx_decState_0.decAnaElapsedCount = 0;
			}
			dtx_decState_0.decAnaElapsedCount += 1;
			dtx_decState_0.dtxHangoverAdded = 0;
			GloabFunc_Dec.DTXStateType dTXStateType2 = GloabFunc_Dec.DTXStateType.SPEECH;
			if (DefineConstants_Dec.table_DTX[(int)frame_type] != 0)
			{
				dTXStateType2 = GloabFunc_Dec.DTXStateType.DTX;
				if (frame_type == RXFrameType.RX_NO_DATA & dTXStateType == GloabFunc_Dec.DTXStateType.SPEECH)
				{
					dTXStateType2 = GloabFunc_Dec.DTXStateType.SPEECH;
				}
			}
			if (dTXStateType2 == GloabFunc_Dec.DTXStateType.SPEECH)
			{
				dtx_decState_0.dtxHangoverCount = 7;
			}
			else
			{
				if (dtx_decState_0.decAnaElapsedCount > 30)
				{
					dtx_decState_0.dtxHangoverAdded = 1;
					dtx_decState_0.decAnaElapsedCount = 0;
					dtx_decState_0.dtxHangoverCount = 0;
				}
				else
				{
					if (dtx_decState_0.dtxHangoverCount == 0)
					{
						dtx_decState_0.decAnaElapsedCount = 0;
					}
					else
					{
						dtx_decState_0.dtxHangoverCount -= 1;
					}
				}
			}
			if (dTXStateType != GloabFunc_Dec.DTXStateType.SPEECH)
			{
				dtx_decState_0.sid_frame = 0;
				dtx_decState_0.valid_data = 0;
				if (frame_type == RXFrameType.RX_SID_FIRST)
				{
					dtx_decState_0.sid_frame = 1;
				}
				else
				{
					if (frame_type == RXFrameType.RX_SID_UPDATE)
					{
						dtx_decState_0.sid_frame = 1;
						dtx_decState_0.valid_data = 1;
					}
					else
					{
						if (frame_type == RXFrameType.RX_SID_BAD)
						{
							dtx_decState_0.sid_frame = 1;
							dtx_decState_0.dtxHangoverAdded = 0;
						}
					}
				}
			}
			return dTXStateType;
		}
		private static void Lsf_lsp(int[] int_0, int[] int_1)
		{
			for (int i = 0; i < 10; i++)
			{
				int num = int_0[i] >> 8;
				int num2 = int_0[i] & 255;
				int num3 = (DefineConstants_Dec.cos_table[num + 1] - DefineConstants_Dec.cos_table[num]) * num2 << 1;
				int_1[i] = DefineConstants_Dec.cos_table[num] + (num3 >> 9);
			}
		}
		private static void D_plsf_3(GloabFunc_Dec.D_plsfState d_plsfState_0, Mode mode, short short_0, short[] indice, int indiceOffset, int[] lsp1_q, int lsp1_qOffset)
		{
			int[] array = new int[10];
			int[] array2 = new int[10];
			int num;
			if (short_0 != 0)
			{
				for (int i = 0; i < 10; i++)
				{
					array2[i] = (d_plsfState_0.past_lsf_q[i] * DefineConstants_Dec.ALPHA >> 15) + (DefineConstants_Dec.mean_lsf_3[i] * DefineConstants_Dec.ONE_ALPHA >> 15);
				}
				if (mode != Mode.MRDTX)
				{
					for (int i = 0; i < 10; i++)
					{
						num = DefineConstants_Dec.mean_lsf_3[i] + (d_plsfState_0.past_r_q[i] * DefineConstants_Dec.pred_fac[i] >> 15);
						d_plsfState_0.past_r_q[i] = array2[i] - num;
					}
				}
				else
				{
					for (int i = 0; i < 10; i++)
					{
						num = DefineConstants_Dec.mean_lsf_3[i] + d_plsfState_0.past_r_q[i];
						d_plsfState_0.past_r_q[i] = array2[i] - num;
					}
				}
			}
			else
			{
				int[] array3;
				int[] dico2_lsf_;
				int[] array4;
				int num2;
				int num3;
				int num4;
				if (mode == Mode.MR475 | mode == Mode.MR515)
				{
					array3 = DefineConstants_Dec.dico1_lsf_3;
					dico2_lsf_ = DefineConstants_Dec.dico2_lsf_3;
					array4 = DefineConstants_Dec.mr515_3_lsf;
					num2 = 0;
					num3 = 0;
					num4 = 0;
				}
				else
				{
					if (mode == Mode.MR795)
					{
						array3 = DefineConstants_Dec.mr795_1_lsf;
						dico2_lsf_ = DefineConstants_Dec.dico2_lsf_3;
						array4 = DefineConstants_Dec.dico3_lsf_3;
						num2 = 0;
						num3 = 0;
						num4 = 0;
					}
					else
					{
						array3 = DefineConstants_Dec.dico1_lsf_3;
						dico2_lsf_ = DefineConstants_Dec.dico2_lsf_3;
						array4 = DefineConstants_Dec.dico3_lsf_3;
						num2 = 0;
						num3 = 0;
						num4 = 0;
					}
				}
				int num5 = (int)indice[indiceOffset];
				indiceOffset++;
				int[] array5 = array3;
				int num6 = num2 + num5 + num5 + num5;
				num5 = (int)indice[indiceOffset];
				indiceOffset++;
				array[0] = array5[num6];
				num6++;
				array[1] = array5[num6];
				num6++;
				array[2] = array5[num6];
				num6++;
				if (mode == Mode.MR475 | mode == Mode.MR515)
				{
					num5 <<= 1;
				}
				array5 = dico2_lsf_;
				num6 = num3 + num5 + num5 + num5;
				num5 = (int)indice[indiceOffset];
				indiceOffset++;
				array[3] = array5[num6];
				num6++;
				array[4] = array5[num6];
				num6++;
				array[5] = array5[num6];
				num6++;
				array5 = array4;
				num6 = num4 + num5 << 2;
				array[6] = array5[num6];
				num6++;
				array[7] = array5[num6];
				num6++;
				array[8] = array5[num6];
				num6++;
				array[9] = array5[num6];
				num6++;
				if (mode != Mode.MRDTX)
				{
					for (int i = 0; i < 10; i++)
					{
						array2[i] = array[i] + (DefineConstants_Dec.mean_lsf_3[i] + (d_plsfState_0.past_r_q[i] * DefineConstants_Dec.pred_fac[i] >> 15));
					}
					GloabFunc.memcpyInt(d_plsfState_0.past_r_q, 0, array, 0, 10);
				}
				else
				{
					for (int i = 0; i < 10; i++)
					{
						array2[i] = array[i] + (DefineConstants_Dec.mean_lsf_3[i] + d_plsfState_0.past_r_q[i]);
					}
					GloabFunc.memcpyInt(d_plsfState_0.past_r_q, 0, array, 0, 10);
				}
			}
			num = 205;
			for (int i = 0; i < 10; i++)
			{
				if (array2[i] < num)
				{
					array2[i] = num;
				}
				num = array2[i] + 205;
			}
			GloabFunc.memcpyInt(d_plsfState_0.past_lsf_q, 0, array2, 0, 10);
			GloabFunc_Dec.Lsf_lsp(array2, lsp1_q);
		}
		private static int pseudonoise(ref int shift_reg, int no_bits)
		{
			int num = shift_reg;
			int num2 = 0;
			for (int i = 0; i < no_bits; i++)
			{
				int num3 = num & 1;
				if (((long)num & 268435456L) != 0L)
				{
					num3 ^= 1;
				}
				else
				{
					num3 = num3;
				}
				num2 = (num2 << 1 | (num & 1));
				num >>= 1;
				if ((num3 & 1) != 0)
				{
					num |= 1073741824;
				}
			}
			shift_reg = num;
			return num2;
		}
		private static void Lsp_lsf(int[] int_0, int lspOffset, int[] int_1, int lsfOffset)
		{
			int num = 63;
			for (int i = 9; i >= 0; i--)
			{
				while (DefineConstants_Dec.cos_table[num] < int_0[i + lspOffset])
				{
					num--;
				}
				int_1[i + lsfOffset] = ((int_0[i + lspOffset] - DefineConstants_Dec.cos_table[num]) * DefineConstants_Dec.acos_slope[num] + 2048 >> 12) + (num << 8);
			}
		}
		private static void Reorder_lsf(int[] int_0, int lsfOffset, int min_dist)
		{
			int num = min_dist;
			for (int i = 0; i < 10; i++)
			{
				if (int_0[i + lsfOffset] < num)
				{
					int_0[i + lsfOffset] = num;
				}
				num = int_0[i + lsfOffset] + min_dist;
			}
		}
		private static void Get_lsp_pol(int[] int_0, int lspOffset, int[] int_1, int fOffset)
		{
			int num = -int_0[lspOffset] << 10;
			int num2 = int_0[lspOffset + 2];
			int num3 = int_0[lspOffset + 4];
			int num4 = int_0[lspOffset + 6];
			int num5 = int_0[lspOffset + 8];
			int num6 = 16777216 << 1;
			num6 = 33554432 - ((num >> 16) * num2 + ((num & 65534) * num2 >> 16) << 2);
			num -= num2 << 10;
			int num7 = num << 1;
			num7 -= (num6 >> 16) * num3 + ((num6 & 65534) * num3 >> 16) << 2;
			num6 += 16777216;
			num6 -= (num >> 16) * num3 + ((num & 65534) * num3 >> 16) << 2;
			num -= num3 << 10;
			int num8 = num6 << 1;
			num8 -= (num7 >> 16) * num4 + ((num7 & 65534) * num4 >> 16) << 2;
			num7 += num;
			num7 -= (num6 >> 16) * num4 + ((num6 & 65534) * num4 >> 16) << 2;
			num6 += 16777216;
			num6 -= (num >> 16) * num4 + ((num & 65534) * num4 >> 16) << 2;
			num -= num4 << 10;
			int num9 = num7 << 1;
			num9 -= (num8 >> 16) * num5 + ((num8 & 65534) * num5 >> 16) << 2;
			num8 += num6;
			num8 -= (num7 >> 16) * num5 + ((num7 & 65534) * num5 >> 16) << 2;
			num7 += num;
			num7 -= (num6 >> 16) * num5 + ((num6 & 65534) * num5 >> 16) << 2;
			num6 += 16777216;
			num6 -= (num >> 16) * num5 + ((num & 65534) * num5 >> 16) << 2;
			num -= num5 << 10;
			int_1[fOffset] = 16777216;
			int_1[fOffset + 1] = num;
			int_1[fOffset + 2] = num6;
			int_1[fOffset + 3] = num7;
			int_1[fOffset + 4] = num8;
			int_1[fOffset + 5] = num9;
		}
		private static void Lsp_Az(int[] int_0, int lspOffset, int[] int_1, int aOffset)
		{
			int[] array = new int[6];
			int[] array2 = new int[6];
			GloabFunc_Dec.Get_lsp_pol(int_0, lspOffset, array, 0);
			GloabFunc_Dec.Get_lsp_pol(int_0, lspOffset + 1, array2, 0);
			int i;
			for (i = 5; i > 0; i--)
			{
				array[i] += array[i - 1];
				array2[i] -= array2[i - 1];
			}
			int_1[aOffset] = 4096;
			i = 1;
			int num = 10;
			while (i <= 5)
			{
				int num2 = array[i] + array2[i];
				int_1[i + aOffset] = (int)((short)(num2 >> 13));
				if ((num2 & 4096) != 0)
				{
					int_1[i + aOffset]++;
				}
				num2 = array[i] - array2[i];
				int_1[num + aOffset] = (int)((short)(num2 >> 13));
				if ((num2 & 4096) != 0)
				{
					int_1[num + aOffset]++;
				}
				i++;
				num--;
			}
		}
		private static void A_Refl(int[] int_0, int aOffset, int[] refl, int ref1Offset)
		{
			int[] array = new int[10];
			int[] array2 = new int[10];
			GloabFunc.memcpyInt(array, 0, int_0, aOffset, 10);
			int i = 9;
			while (i >= 0)
			{
				if (Math.Abs(array[i]) < 4096)
				{
					refl[i + ref1Offset] = array[i] << 3;
					int num = refl[i + ref1Offset] * refl[i + ref1Offset] << 1;
					int num2 = 2147483647 - num;
					int num3 = 0;
					if (num2 != 0)
					{
						num = num2;
						while ((num & 1073741824) == 0)
						{
							num3++;
							num <<= 1;
						}
					}
					else
					{
						num3 = 0;
					}
					int num4 = 15 - num3;
					num2 <<= num3;
					num = num2 + 32768;
					int num6;
					if (num > 0)
					{
						int num5 = num >> 16;
						num6 = 536870912 / num5;
					}
					else
					{
						num6 = 16384;
					}
					for (int j = 0; j < i; j++)
					{
						num2 = array[j] << 16;
						num2 -= refl[i + ref1Offset] * array[i - j - 1] << 1;
						num = num2 + 32768 >> 16;
						num = num6 * num << 1;
						if (num4 > 0)
						{
							if ((num & 1 << num4 - 1) != 0)
							{
								num = (num >> num4) + 1;
							}
							else
							{
								num >>= num4;
							}
						}
						else
						{
							num >>= num4;
						}
						if (Math.Abs(num) > 32767)
						{
							goto IL_14A;
						}
						array2[j] = num;
					}
					GloabFunc.memcpyInt(array, 0, array2, 0, i);
					i--;
					continue;
				}
				IL_14A:
				GloabFunc.memsetInt(refl, ref1Offset, 0, 40);
				return;
			}
		}
		private static void Log2_norm(int int_0, int int_1, ref int exponent, ref int fraction)
		{
			if (int_0 <= 0)
			{
				exponent = 0;
				fraction = 0;
				return;
			}
			int num = int_0 >> 25;
			num -= 32;
			int num2 = int_0 >> 9;
			num2 &= 65534;
			int num3 = (DefineConstants_Dec.log2_table[num] << 16) - num2 * (DefineConstants_Dec.log2_table[num] - DefineConstants_Dec.log2_table[num + 1]);
			fraction = num3 >> 16;
			exponent = 30 - int_1;
		}
		private static void Log2(int int_0, ref int exponent, ref int fraction)
		{
			int num = 0;
			if (int_0 != 0)
			{
				int num2 = int_0;
				while ((((long)num2 & (long)((ulong)-2147483648)) ^ (long)((long)(num2 & 1073741824) << 1)) == 0L)
				{
					num++;
					num2 <<= 1;
				}
			}
			GloabFunc_Dec.Log2_norm(int_0 << num, num, ref exponent, ref fraction);
		}
		private static int Pow2(int exponent, int fraction)
		{
			int num = fraction >> 10;
			int num2 = fraction << 5 & 32767;
			int num3 = DefineConstants_Dec.pow2_table[num] << 16;
			int num4 = DefineConstants_Dec.pow2_table[num] - DefineConstants_Dec.pow2_table[num + 1];
			num3 -= num4 * num2 << 1;
			if (exponent >= -1)
			{
				int num5 = 30 - exponent;
				if ((num3 & 1 << num5 - 1) != 0)
				{
					num3 = (num3 >> num5) + 1;
				}
				else
				{
					num3 >>= num5;
				}
			}
			else
			{
				num3 = 0;
			}
			return num3;
		}
		private static void Build_CN_code(ref int seed, int[] int_0, int codOffset)
		{
			GloabFunc.memsetInt(int_0, codOffset, 0, 160);
			for (int i = 0; i < 10; i++)
			{
				int num = GloabFunc_Dec.pseudonoise(ref seed, 2);
				num = num * 20 >> 1;
				num += i;
				int num2 = GloabFunc_Dec.pseudonoise(ref seed, 1);
				if (num2 > 0)
				{
					int_0[num + codOffset] = 4096;
				}
				else
				{
					int_0[num + codOffset] = -4096;
				}
			}
		}
		private static void Build_CN_param(ref short seed, Mode mode, short[] parm, int parmOffset)
		{
			seed = (short)((long)(seed * 31821) + 13849L);
			int[] window_200_ = DefineConstants_Dec.window_200_40;
			int num = (int)(seed & 127);
			switch (mode)
			{
			case Mode.MR475:
				for (int i = 0; i < 17; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR475[i]));
				}
				return;
			case Mode.MR515:
				for (int i = 0; i < 19; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR515[i]));
				}
				return;
			case Mode.MR59:
				for (int i = 0; i < 19; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR59[i]));
				}
				return;
			case Mode.MR67:
				for (int i = 0; i < 19; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR67[i]));
				}
				return;
			case Mode.MR74:
				for (int i = 0; i < 19; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR74[i]));
				}
				return;
			case Mode.MR795:
				for (int i = 0; i < 23; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR795[i]));
				}
				return;
			case Mode.MR102:
				for (int i = 0; i < 39; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR102[i]));
				}
				return;
			case Mode.MR122:
				for (int i = 0; i < 57; i++)
				{
					parm[parmOffset + i] = (short)(window_200_[num++] & ~(65535 << (int)GloabFunc_Dec.bitno_MR122[i]));
				}
				return;
			default:
				return;
			}
		}
		private static int Syn_filt(int[] int_0, int aOffset, int[] int_1, int xOffset, int[] int_2, int yOffset, int int_3, int[] int_4, int memOffset, int update)
		{
			int[] array = new int[50];
			int result = 0;
			GloabFunc.memcpyInt(array, 0, int_4, memOffset, 10);
			int[] array2 = array;
			int i = 10;
			int num = 10 + int_3;
			int num2 = int_0[aOffset];
			while (i < num)
			{
				int num3 = int_1[xOffset++] * num2;
				num3 -= array2[-1 + i] * int_0[1 + aOffset];
				num3 -= array2[-2 + i] * int_0[2 + aOffset];
				num3 -= array2[-3 + i] * int_0[3 + aOffset];
				num3 -= array2[-4 + i] * int_0[4 + aOffset];
				num3 -= array2[-5 + i] * int_0[5 + aOffset];
				num3 -= array2[-6 + i] * int_0[6 + aOffset];
				num3 -= array2[-7 + i] * int_0[7 + aOffset];
				num3 -= array2[-8 + i] * int_0[8 + aOffset];
				num3 -= array2[-9 + i] * int_0[9 + aOffset];
				num3 -= array2[-10 + i] * int_0[10 + aOffset];
				if (Math.Abs(num3) < 134217727)
				{
					array2[i] = num3 + 2048 >> 12;
				}
				else
				{
					if (num3 > 0)
					{
						array2[i] = 32767;
						result = 1;
					}
					else
					{
						array2[i] = -32768;
						result = 1;
					}
				}
				i++;
			}
			GloabFunc.memcpyInt(int_2, yOffset, array, 10, int_3);
			if (update != 0)
			{
				GloabFunc.memcpyInt(int_4, memOffset, int_2, yOffset + int_3 - 10, 10);
			}
			return result;
		}
		private static void Syn_filt_overflow(int[] int_0, int aOffset, int[] int_1, int xOffset, int[] int_2, int yOffset, int int_3, int[] int_4, int memOffset, int update)
		{
			int[] array = new int[50];
			GloabFunc.memcpyInt(array, 0, int_4, memOffset, 10);
			int[] array2 = array;
			int num = 10;
			int num2 = int_0[aOffset];
			for (int i = 0; i < int_3; i++)
			{
				int num3 = int_1[i + xOffset] * num2;
				for (int j = 1; j <= 10; j++)
				{
					num3 -= int_0[j + aOffset] * array2[-j + num];
					if (num3 > 1073741823)
					{
						num3 = 1073741823;
					}
					else
					{
						if (num3 < -1073741824)
						{
							num3 = -1073741824;
						}
					}
				}
				if (Math.Abs(num3) < 134211584)
				{
					array2[num] = num3 + 2048 >> 12;
				}
				else
				{
					if (num3 > 0)
					{
						array2[num] = 32767;
					}
					else
					{
						array2[num] = -32768;
					}
				}
				num++;
			}
			GloabFunc.memcpyInt(int_2, yOffset, array, 10, int_3);
			if (update != 0)
			{
				GloabFunc.memcpyInt(int_4, memOffset, int_2, yOffset + int_3 - 10, 10);
			}
		}
		private static void dtx_dec(GloabFunc_Dec.dtx_decState dtx_decState_0, int[] mem_syn, int mem_synOffset, GloabFunc_Dec.D_plsfState lsfState, GloabFunc_Dec.gc_predState pred_state, GloabFunc_Dec.Cb_gain_averageState averState, GloabFunc_Dec.DTXStateType new_state, Mode mode, short[] parm, int parmOffset, int[] synth, int synthOffset, int[] A_t, int A_tOffset)
		{
			int[] array = new int[40];
			int[] array2 = new int[11];
			int[] array3 = new int[11];
			int[] array4 = new int[10];
			int[] array5 = new int[10];
			int[] array6 = new int[10];
			int[] array7 = new int[10];
			int[] array8 = new int[10];
			int[] array9 = new int[10];
			if (dtx_decState_0.dtxHangoverAdded != 0 & dtx_decState_0.sid_frame != 0)
			{
				dtx_decState_0.log_en_adjust = DefineConstants_Dec.dtx_log_en_adjust[(int)mode];
				int num = (int)(dtx_decState_0.lsf_hist_ptr + 10);
				if (num == 80)
				{
					num = 0;
				}
				GloabFunc.memcpyInt(dtx_decState_0.lsf_hist, num, dtx_decState_0.lsf_hist, (int)dtx_decState_0.lsf_hist_ptr, 10);
				num = (int)(dtx_decState_0.log_en_hist_ptr + 1);
				if (num == 8)
				{
					num = 0;
				}
				dtx_decState_0.log_en_hist[num] = dtx_decState_0.log_en_hist[(int)dtx_decState_0.log_en_hist_ptr];
				dtx_decState_0.log_en = 0;
				GloabFunc.memsetInt(array6, 0, 0, 40);
				for (int i = 0; i < 8; i++)
				{
					dtx_decState_0.log_en += dtx_decState_0.log_en_hist[i] >> 3;
					for (int j = 0; j < 10; j++)
					{
						array6[j] += dtx_decState_0.lsf_hist[i * 10 + j];
					}
				}
				for (int j = 0; j < 10; j++)
				{
					array6[j] >>= 3;
				}
				GloabFunc_Dec.Lsf_lsp(array6, dtx_decState_0.int_0);
				dtx_decState_0.log_en -= (int)dtx_decState_0.log_en_adjust;
				GloabFunc.memcpyInt(dtx_decState_0.lsf_hist_mean, 0, dtx_decState_0.lsf_hist, 0, 80);
				for (int i = 0; i < 10; i++)
				{
					int num2 = 0;
					for (int j = 0; j < 8; j++)
					{
						num2 += dtx_decState_0.lsf_hist_mean[i + j * 10];
					}
					num2 >>= 3;
					for (int j = 0; j < 8; j++)
					{
						dtx_decState_0.lsf_hist_mean[i + j * 10] = dtx_decState_0.lsf_hist_mean[i + j * 10] - num2;
						dtx_decState_0.lsf_hist_mean[i + j * 10] = dtx_decState_0.lsf_hist_mean[i + j * 10] * (int)DefineConstants_Dec.lsf_hist_mean_scale[i] >> 15;
						int num3;
						if (dtx_decState_0.lsf_hist_mean[i + j * 10] < 0)
						{
							num3 = 1;
						}
						else
						{
							num3 = 0;
						}
						dtx_decState_0.lsf_hist_mean[i + j * 10] = Math.Abs(dtx_decState_0.lsf_hist_mean[i + j * 10]);
						if (dtx_decState_0.lsf_hist_mean[i + j * 10] > 655)
						{
							dtx_decState_0.lsf_hist_mean[i + j * 10] = 655 + (dtx_decState_0.lsf_hist_mean[i + j * 10] - 655 >> 2);
						}
						if (dtx_decState_0.lsf_hist_mean[i + j * 10] > 1310)
						{
							dtx_decState_0.lsf_hist_mean[i + j * 10] = 1310;
						}
						if (num3 != 0)
						{
							dtx_decState_0.lsf_hist_mean[i + j * 10] = -dtx_decState_0.lsf_hist_mean[i + j * 10];
						}
					}
				}
			}
			if (dtx_decState_0.sid_frame != 0)
			{
				GloabFunc.memcpyInt(dtx_decState_0.lsp_old, 0, dtx_decState_0.int_0, 0, 10);
				dtx_decState_0.old_log_en = dtx_decState_0.log_en;
				if (dtx_decState_0.valid_data != 0)
				{
					short num4 = dtx_decState_0.since_last_sid;
					dtx_decState_0.since_last_sid = 0;
					if (num4 > 32)
					{
						num4 = 32;
					}
					if (num4 >= 2)
					{
						dtx_decState_0.true_sid_period_inv = 33554432 / ((int)num4 << 10);
					}
					else
					{
						dtx_decState_0.true_sid_period_inv = 16384;
					}
					GloabFunc.memcpyInt(lsfState.past_r_q, 0, DefineConstants_Dec.past_rq_init, (int)(parm[parmOffset] * 10), 10);
					GloabFunc_Dec.D_plsf_3(lsfState, Mode.MRDTX, 0, parm, parmOffset + 1, dtx_decState_0.int_0, 0);
					GloabFunc.memsetInt(lsfState.past_r_q, 0, 0, 40);
					short num5 = parm[4 + parmOffset];
					dtx_decState_0.log_en = (int)((short)(num5 << 9));
					dtx_decState_0.log_en = (int)((short)(dtx_decState_0.log_en - 5120));
					if (num5 == 0)
					{
						dtx_decState_0.log_en = -32768;
					}
					if (dtx_decState_0.data_updated == 0 || dtx_decState_0.dtxGlobalState == GloabFunc_Dec.DTXStateType.SPEECH)
					{
						GloabFunc.memcpyInt(dtx_decState_0.lsp_old, 0, dtx_decState_0.int_0, 0, 10);
						dtx_decState_0.old_log_en = dtx_decState_0.log_en;
					}
				}
				short num6 = (short)((dtx_decState_0.log_en >> 1) - 9000);
				if (num6 > 0)
				{
					num6 = 0;
				}
				if (num6 < -14436)
				{
					num6 = -14436;
				}
				pred_state.past_qua_en[0] = (int)num6;
				pred_state.past_qua_en[1] = (int)num6;
				pred_state.past_qua_en[2] = (int)num6;
				pred_state.past_qua_en[3] = (int)num6;
				num6 = (short)(5443 * num6 >> 15);
				pred_state.past_qua_en_MR122[0] = (int)num6;
				pred_state.past_qua_en_MR122[1] = (int)num6;
				pred_state.past_qua_en_MR122[2] = (int)num6;
				pred_state.past_qua_en_MR122[3] = (int)num6;
			}
			dtx_decState_0.log_en_adjust = (short)((dtx_decState_0.log_en_adjust * 29491 >> 15) + (((int)DefineConstants_Dec.dtx_log_en_adjust[(int)mode] << 5) * 3277 >> 20));
			int num7;
			if (dtx_decState_0.since_last_sid > 30)
			{
				num7 = 32767;
			}
			else
			{
				num7 = (int)((short)(dtx_decState_0.since_last_sid + 1 << 10));
			}
			num7 = num7 * dtx_decState_0.true_sid_period_inv >> 15;
			if (num7 > 1024)
			{
				num7 = 1024;
			}
			num7 = (int)((short)(num7 << 4));
			int num8 = num7 * dtx_decState_0.log_en << 1;
			for (int i = 0; i < 10; i++)
			{
				array4[i] = num7 * dtx_decState_0.int_0[i] >> 15;
			}
			num7 = 16384 - num7;
			num8 += num7 * dtx_decState_0.old_log_en << 1;
			for (int i = 0; i < 10; i++)
			{
				array4[i] += num7 * dtx_decState_0.lsp_old[i] >> 15;
				array4[i] <<= 1;
			}
			int num9 = (int)(dtx_decState_0.log_pg_mean - 2457);
			num9 = 4096 - (num9 * 9830 >> 15);
			if (num9 >= 4096)
			{
				num9 = 32767;
			}
			else
			{
				if (num9 < 0)
				{
					num9 = 0;
				}
				else
				{
					num9 <<= 3;
				}
			}
			int num10 = GloabFunc_Dec.pseudonoise(ref dtx_decState_0.pn_seed_rx, 3);
			GloabFunc_Dec.Lsp_lsf(array4, 0, array7, 0);
			GloabFunc.memcpyInt(array8, 0, array7, 0, 10);
			for (int i = 0; i < 10; i++)
			{
				array8[i] += num9 * dtx_decState_0.lsf_hist_mean[i + num10 * 10] >> 15;
			}
			GloabFunc_Dec.Reorder_lsf(array7, 0, 205);
			GloabFunc_Dec.Reorder_lsf(array8, 0, 205);
			GloabFunc.memcpyInt(lsfState.past_lsf_q, 0, array7, 0, 10);
			GloabFunc_Dec.Lsf_lsp(array7, array4);
			GloabFunc_Dec.Lsf_lsp(array8, array9);
			GloabFunc_Dec.Lsp_Az(array4, 0, array2, 0);
			GloabFunc_Dec.Lsp_Az(array9, 0, array3, 0);
			GloabFunc.memcpyInt(A_t, A_tOffset, array2, 0, 11);
			GloabFunc.memcpyInt(A_t, A_tOffset + 11, array2, 0, 11);
			GloabFunc.memcpyInt(A_t, A_tOffset + 11 << 1, array2, 0, 11);
			GloabFunc.memcpyInt(A_t, A_tOffset + 11 + 11 + 11, array2, 0, 11);
			GloabFunc_Dec.A_Refl(array2, 1, array5, 0);
			int num11 = 32767;
			for (int i = 0; i < 10; i++)
			{
				num11 = num11 * (32767 - (array5[i] * array5[i] >> 15)) >> 15;
			}
			int num12 = 0;
			int num13 = 0;
			GloabFunc_Dec.Log2(num11, ref num12, ref num13);
			int num14 = num12 - 15 << 12;
			if (num14 < -32768)
			{
				num14 = -32768;
			}
			num14 = -(num14 + (num13 >> 3)) >> 1;
			dtx_decState_0.log_pg_mean = (short)((29491 * dtx_decState_0.log_pg_mean >> 15) + (3277 * num14 >> 15));
			num8 >>= 10;
			num8 += 262144;
			num8 -= num14 << 4;
			num8 += (int)dtx_decState_0.log_en_adjust << 5;
			short num15 = (short)(num8 >> 16);
			short fraction = (short)(num8 - ((int)num15 << 16) >> 1);
			short num16 = (short)GloabFunc_Dec.Pow2((int)num15, (int)fraction);
			for (int i = 0; i < 4; i++)
			{
				GloabFunc_Dec.Build_CN_code(ref dtx_decState_0.pn_seed_rx, array, 0);
				for (int j = 0; j < 40; j++)
				{
					array[j] = (int)num16 * array[j] >> 15;
				}
				GloabFunc_Dec.Syn_filt(array3, 0, array, 0, synth, synthOffset + i * 40, 40, mem_syn, mem_synOffset, 1);
			}
			averState.hangVar = 20;
			averState.hangCount = 0;
			if (new_state == GloabFunc_Dec.DTXStateType.DTX_MUTE)
			{
				short num4 = dtx_decState_0.since_last_sid;
				if (num4 > 32)
				{
					num4 = 32;
				}
				if (num4 == 1)
				{
					dtx_decState_0.true_sid_period_inv = 32767;
				}
				else
				{
					int num17 = 1024;
					int num18 = (int)num4 << 10;
					dtx_decState_0.true_sid_period_inv = 0;
					for (int i = 0; i < 15; i++)
					{
						dtx_decState_0.true_sid_period_inv <<= 1;
						num17 <<= 1;
						if (num17 >= num18)
						{
							num17 -= num18;
							dtx_decState_0.true_sid_period_inv++;
						}
					}
				}
				dtx_decState_0.since_last_sid = 0;
				GloabFunc.memcpyInt(dtx_decState_0.lsp_old, 0, dtx_decState_0.int_0, 0, 10);
				dtx_decState_0.old_log_en = dtx_decState_0.log_en;
				dtx_decState_0.log_en -= 256;
				if (dtx_decState_0.log_en < -32768)
				{
					dtx_decState_0.log_en = -32768;
				}
			}
			if (dtx_decState_0.sid_frame != 0 & (dtx_decState_0.valid_data != 0 || (dtx_decState_0.valid_data == 0 & dtx_decState_0.dtxHangoverAdded != 0)))
			{
				dtx_decState_0.since_last_sid = 0;
				dtx_decState_0.data_updated = 1;
			}
		}
		private static void lsp_avg(GloabFunc_Dec.lsp_avgState lsp_avgState_0, int[] int_0, int lspOffset)
		{
			for (int i = 0; i < 10; i++)
			{
				int num = lsp_avgState_0.lsp_meanSave[i] << 16;
				num -= 5243 * lsp_avgState_0.lsp_meanSave[i] << 1;
				num += 5243 * int_0[i + lspOffset] << 1;
				num += 32768;
				lsp_avgState_0.lsp_meanSave[i] = num >> 16;
			}
		}
		private static void Int_lpc_1and3(int[] lsp_old, int lsp_oldOffset, int[] lsp_mid, int lsp_midOffset, int[] lsp_new, int lsp_newOffset, int[] Az, int AzOffset)
		{
			int[] array = new int[10];
			for (int i = 0; i < 10; i++)
			{
				array[i] = (lsp_mid[i + lsp_midOffset] >> 1) + (lsp_old[i + lsp_oldOffset] >> 1);
			}
			GloabFunc_Dec.Lsp_Az(array, 0, Az, AzOffset);
			AzOffset += 11;
			GloabFunc_Dec.Lsp_Az(lsp_mid, lsp_midOffset, Az, AzOffset);
			AzOffset += 11;
			for (int i = 0; i < 10; i++)
			{
				array[i] = (lsp_mid[i + lsp_midOffset] >> 1) + (lsp_new[i + lsp_newOffset] >> 1);
			}
			GloabFunc_Dec.Lsp_Az(array, 0, Az, AzOffset);
			AzOffset += 11;
			GloabFunc_Dec.Lsp_Az(lsp_new, lsp_newOffset, Az, AzOffset);
		}
		private static void Int_lpc_1to3(int[] lsp_old, int lsp_oldOffset, int[] lsp_new, int lsp_newOffset, int[] Az, int AzOffset)
		{
			int[] array = new int[10];
			for (int i = 0; i < 10; i++)
			{
				array[i] = (lsp_new[i + lsp_newOffset] >> 2) + (lsp_old[i + lsp_oldOffset] - (lsp_old[i + lsp_oldOffset] >> 2));
			}
			GloabFunc_Dec.Lsp_Az(array, 0, Az, AzOffset);
			AzOffset += 11;
			for (int i = 0; i < 10; i++)
			{
				array[i] = (lsp_old[i + lsp_oldOffset] >> 1) + (lsp_new[i + lsp_newOffset] >> 1);
			}
			GloabFunc_Dec.Lsp_Az(array, 0, Az, AzOffset);
			AzOffset += 11;
			for (int i = 0; i < 10; i++)
			{
				array[i] = (lsp_old[i + lsp_oldOffset] >> 2) + (lsp_new[i + lsp_newOffset] - (lsp_new[i + lsp_newOffset] >> 2));
			}
			GloabFunc_Dec.Lsp_Az(array, 0, Az, AzOffset);
			AzOffset += 11;
			GloabFunc_Dec.Lsp_Az(lsp_new, lsp_newOffset, Az, AzOffset);
		}
		private static void D_plsf_5(GloabFunc_Dec.D_plsfState d_plsfState_0, short short_0, short[] indice, int indiceOffset, int[] lsp1_q, int[] lsp2_q)
		{
			int[] array = new int[10];
			int[] array2 = new int[10];
			int[] array3 = new int[10];
			int[] array4 = new int[10];
			if (short_0 != 0)
			{
				for (int i = 0; i < 10; i += 2)
				{
					array3[i] = (d_plsfState_0.past_lsf_q[i] * DefineConstants_Dec.ALPHA_122 >> 15) + (DefineConstants_Dec.mean_lsf_5[i] * DefineConstants_Dec.ONE_ALPHA_122 >> 15);
					array3[i + 1] = (d_plsfState_0.past_lsf_q[i + 1] * DefineConstants_Dec.ALPHA_122 >> 15) + (DefineConstants_Dec.mean_lsf_5[i + 1] * DefineConstants_Dec.ONE_ALPHA_122 >> 15);
				}
				GloabFunc.memcpyInt(array4, 0, array3, 0, 10);
				for (int i = 0; i < 10; i += 2)
				{
					int num = DefineConstants_Dec.mean_lsf_5[i] + (d_plsfState_0.past_r_q[i] * 21299 >> 15);
					int num2 = DefineConstants_Dec.mean_lsf_5[i + 1] + (d_plsfState_0.past_r_q[i + 1] * 21299 >> 15);
					d_plsfState_0.past_r_q[i] = array4[i] - num;
					d_plsfState_0.past_r_q[i + 1] = array4[i + 1] - num2;
				}
			}
			else
			{
				int[] array5 = DefineConstants_Dec.dico1_lsf_5;
				int num3 = (int)indice[indiceOffset] << 2;
				array[0] = array5[num3++];
				array[1] = array5[num3++];
				array2[0] = array5[num3++];
				array2[1] = array5[num3++];
				array5 = DefineConstants_Dec.dico2_lsf_5;
				num3 = (int)indice[1 + indiceOffset] << 2;
				array[2] = array5[num3++];
				array[3] = array5[num3++];
				array2[2] = array5[num3++];
				array2[3] = array5[num3++];
				int num4 = (int)(indice[2 + indiceOffset] & 1);
				int i = indice[2 + indiceOffset] >> 1;
				array5 = DefineConstants_Dec.dico3_lsf_5;
				num3 = i << 2;
				if (num4 == 0)
				{
					array[4] = array5[num3++];
					array[5] = array5[num3++];
					array2[4] = array5[num3++];
					array2[5] = array5[num3++];
				}
				else
				{
					array[4] = (int)((short)(-(short)array5[num3++]));
					array[5] = (int)((short)(-(short)array5[num3++]));
					array2[4] = (int)((short)(-(short)array5[num3++]));
					array2[5] = (int)((short)(-(short)array5[num3++]));
				}
				array5 = DefineConstants_Dec.dico4_lsf_5;
				num3 = (int)indice[3 + indiceOffset] << 2;
				array[6] = array5[num3++];
				array[7] = array5[num3++];
				array2[6] = array5[num3++];
				array2[7] = array5[num3++];
				array5 = DefineConstants_Dec.dico5_lsf_5;
				num3 = (int)indice[4 + indiceOffset] << 2;
				array[8] = array5[num3++];
				array[9] = array5[num3++];
				array2[8] = array5[num3++];
				array2[9] = array5[num3++];
				for (i = 0; i < 10; i++)
				{
					int num = DefineConstants_Dec.mean_lsf_5[i] + (d_plsfState_0.past_r_q[i] * 21299 >> 15);
					array3[i] = array[i] + num;
					array4[i] = array2[i] + num;
					d_plsfState_0.past_r_q[i] = array2[i];
				}
			}
			GloabFunc_Dec.Reorder_lsf(array3, 0, 205);
			GloabFunc_Dec.Reorder_lsf(array4, 0, 205);
			GloabFunc.memcpyInt(d_plsfState_0.past_lsf_q, 0, array4, 0, 10);
			GloabFunc_Dec.Lsf_lsp(array3, lsp1_q);
			GloabFunc_Dec.Lsf_lsp(array4, lsp2_q);
		}
		private static void Dec_lag3(int index, int t0_min, int t0_max, int i_subfr, int T0_prev, ref int T0, ref int T0_frac, int flag4)
		{
			if (i_subfr == 0)
			{
				if (index < 197)
				{
					T0 = ((index + 2) * 10923 >> 15) + 19;
					int num = T0 + T0 + T0;
					T0_frac = index - num + 58;
					return;
				}
				T0 = index - 112;
				T0_frac = 0;
				return;
			}
			else
			{
				int num;
				if (flag4 == 0)
				{
					num = ((index + 2) * 10923 >> 15) - 1;
					T0 = num + t0_min;
					num = num + num + num;
					T0_frac = index - 2 - num;
					return;
				}
				int num2 = T0_prev;
				if (num2 - t0_min > 5)
				{
					num2 = t0_min + 5;
				}
				if (t0_max - num2 > 4)
				{
					num2 = t0_max - 4;
				}
				if (index < 4)
				{
					num = num2 - 5;
					T0 = num + index;
					T0_frac = 0;
					return;
				}
				if (index < 12)
				{
					num = ((index - 5) * 10923 >> 15) - 1;
					T0 = num + num2;
					num = num + num + num;
					T0_frac = index - 9 - num;
					return;
				}
				num = index - 12 + num2;
				T0 = num + 1;
				T0_frac = 0;
				return;
			}
		}
		private static void Pred_lt_3or6_40(int[] int_0, int excOffset, int T0, int frac, int flag3)
		{
			int num = excOffset - T0;
			frac = -frac;
			if (flag3 != 0)
			{
				frac <<= 1;
			}
			if (frac < 0)
			{
				frac += 6;
				num--;
			}
			int[] inter = DefineConstants_Dec.inter6;
			int num2 = frac;
			int[] inter2 = DefineConstants_Dec.inter6;
			int num3 = 6 - frac;
			for (int i = 0; i < 40; i++)
			{
				int num4 = num++;
				int num5 = num;
				int num6 = int_0[num4] * inter[num2];
				num6 += int_0[-1 + num4] * inter[6 + num2];
				num6 += int_0[-2 + num4] * inter[12 + num2];
				num6 += int_0[-3 + num4] * inter[18 + num2];
				num6 += int_0[-4 + num4] * inter[24 + num2];
				num6 += int_0[-5 + num4] * inter[30 + num2];
				num6 += int_0[-6 + num4] * inter[36 + num2];
				num6 += int_0[-7 + num4] * inter[42 + num2];
				num6 += int_0[-8 + num4] * inter[48 + num2];
				num6 += int_0[-9 + num4] * inter[54 + num2];
				num6 += int_0[num5] * inter2[num3];
				num6 += int_0[1 + num5] * inter2[6 + num3];
				num6 += int_0[2 + num5] * inter2[12 + num3];
				num6 += int_0[3 + num5] * inter2[18 + num3];
				num6 += int_0[4 + num5] * inter2[24 + num3];
				num6 += int_0[5 + num5] * inter2[30 + num3];
				num6 += int_0[6 + num5] * inter2[36 + num3];
				num6 += int_0[7 + num5] * inter2[42 + num3];
				num6 += int_0[8 + num5] * inter2[48 + num3];
				num6 += int_0[9 + num5] * inter2[54 + num3];
				int_0[i + excOffset] = num6 + 16384 >> 15;
			}
		}
		private static void Dec_lag6(int index, int pit_min, int pit_max, int i_subfr, ref int T0, ref int T0_frac)
		{
			if (i_subfr != 0)
			{
				int num = T0 - 5;
				if (num < pit_min)
				{
					num = pit_min;
				}
				int num2 = num + 9;
				if (num2 > pit_max)
				{
					num = pit_max - 9;
				}
				int num3 = (index + 5) / 6 - 1;
				T0 = num3 + num;
				num3 = num3 + num3 + num3;
				T0_frac = index - 3 - (num3 + num3);
				return;
			}
			if (index < 463)
			{
				T0 = (index + 5) / 6 + 17;
				int num3 = T0 + T0 + T0;
				T0_frac = index - (num3 + num3) + 105;
				return;
			}
			T0 = index - 368;
			T0_frac = 0;
		}
		private static void decompress10(int MSBs, int LSBs, int index1, int index2, int index3, int[] pos_indx, int pos_indxOffset)
		{
			if (MSBs > 124)
			{
				MSBs = 124;
			}
			int num = MSBs / 25;
			pos_indx[index1 + pos_indxOffset] = ((MSBs - 25 * num) % 5 << 1) + (LSBs & 1);
			pos_indx[index2 + pos_indxOffset] = ((MSBs - 25 * num) / 5 << 1) + ((LSBs & 2) >> 1);
			pos_indx[index3 + pos_indxOffset] = (num << 1) + (LSBs >> 2);
		}
		private static void decompress_codewords(short[] indx, int indxOffset, int[] pos_indx, int pos_indxOffset)
		{
			int num = indx[indxOffset] >> 3;
			int num2 = (int)(indx[indxOffset] & 7);
			GloabFunc_Dec.decompress10(num, num2, 0, 4, 1, pos_indx, pos_indxOffset);
			num = indx[1 + indxOffset] >> 3;
			num2 = (int)(indx[1 + indxOffset] & 7);
			GloabFunc_Dec.decompress10(num, num2, 2, 6, 5, pos_indx, pos_indxOffset);
			num = indx[2 + indxOffset] >> 2;
			num2 = (int)(indx[2 + indxOffset] & 3);
			int num3 = num * 25 + 12 >> 5;
			int num4 = num3 * 6554 >> 15;
			int num5 = num4 & 1;
			int num6 = num3 - num4 * 5;
			if (num5 == 1)
			{
				num6 = 4 - num6;
			}
			pos_indx[3 + pos_indxOffset] = (num6 << 1) + (num2 & 1);
			pos_indx[7 + pos_indxOffset] = (num4 << 1) + (num2 >> 1);
		}
		private static void decode_2i40_9bits(int subNr, int sign, int index, int[] int_0)
		{
			int[] array = new int[2];
			int i = (index & 64) >> 6;
			int num = index & 7;
			num += num << 2;
			int num2 = (int)DefineConstants_Dec.startPos[(i << 3) + (subNr << 1)];
			array[0] = num + num2;
			index >>= 3;
			num = (index & 7);
			num += num << 2;
			num2 = (int)DefineConstants_Dec.startPos[(i << 3) + (subNr << 1) + 1];
			array[1] = (int)((short)(num + num2));
			GloabFunc.memsetInt(int_0, 0, 0, 160);
			for (i = 0; i < 2; i++)
			{
				num = (sign & 1);
				sign >>= 1;
				if (num != 0)
				{
					int_0[array[i]] = 8191;
				}
				else
				{
					int_0[array[i]] = -8192;
				}
			}
		}
		private static void decode_2i40_11bits(int sign, int index, int[] int_0)
		{
			int[] array = new int[2];
			int i = index & 1;
			index >>= 1;
			int num = index & 7;
			num += num << 2;
			num++;
			i <<= 1;
			array[0] = num + i;
			index >>= 3;
			i = (index & 3);
			index >>= 2;
			num = (index & 7);
			if (i == 3)
			{
				num += num << 2;
				array[1] = num + 4;
			}
			else
			{
				num += num << 2;
				array[1] = num + i;
			}
			GloabFunc.memsetInt(int_0, 0, 0, 160);
			for (i = 0; i < 2; i++)
			{
				num = (sign & 1);
				sign >>= 1;
				if (num != 0)
				{
					int_0[array[i]] = 8191;
				}
				else
				{
					int_0[array[i]] = -8192;
				}
			}
		}
		private static void decode_3i40_14bits(int sign, int index, int[] int_0)
		{
			int[] array = new int[3];
			int num = index & 7;
			array[0] = num + (num << 2);
			index >>= 3;
			int i = index & 1;
			index >>= 1;
			num = (index & 7);
			num += num << 2;
			num++;
			i <<= 1;
			array[1] = num + i;
			index >>= 3;
			i = (index & 1);
			index >>= 1;
			num = (index & 7);
			num += num << 2;
			num += 2;
			i <<= 1;
			array[2] = num + i;
			GloabFunc.memsetInt(int_0, 0, 0, 160);
			for (i = 0; i < 3; i++)
			{
				num = (sign & 1);
				sign >>= 1;
				if (num > 0)
				{
					int_0[array[i]] = 8191;
				}
				else
				{
					int_0[array[i]] = -8192;
				}
			}
		}
		private static void decode_4i40_17bits(int sign, int index, int[] int_0)
		{
			int[] array = new int[4];
			int num = index & 7;
			num = DefineConstants_Dec.dgray[num];
			array[0] = num + (num << 2);
			index >>= 3;
			num = (index & 7);
			num = DefineConstants_Dec.dgray[num];
			num += num << 2;
			array[1] = num + 1;
			index >>= 3;
			num = (index & 7);
			num = DefineConstants_Dec.dgray[num];
			num += num << 2;
			array[2] = num + 2;
			index >>= 3;
			int i = index & 1;
			index >>= 1;
			num = (index & 7);
			num = DefineConstants_Dec.dgray[num];
			num += num << 2;
			num += 3;
			array[3] = num + i;
			GloabFunc.memsetInt(int_0, 0, 0, 160);
			for (i = 0; i < 4; i++)
			{
				num = (sign & 1);
				sign >>= 1;
				if (num != 0)
				{
					int_0[array[i]] = 8191;
				}
				else
				{
					int_0[array[i]] = -8192;
				}
			}
		}
		private static void decode_8i40_31bits(short[] index, int indexOffset, int[] int_0)
		{
			int[] array = new int[8];
			GloabFunc.memsetInt(int_0, 0, 0, 160);
			GloabFunc_Dec.decompress_codewords(index, indexOffset + 4, array, 0);
			for (int i = 0; i < 4; i++)
			{
				int num = array[i];
				num <<= 2;
				int num2 = num + i;
				int num3;
				if (index[i + indexOffset] == 0)
				{
					num3 = 8191;
				}
				else
				{
					num3 = -8191;
				}
				num = array[i + 4];
				num <<= 2;
				int num4 = num + i;
				int_0[num2] = num3;
				if (num4 < num2)
				{
					num3 = -num3;
				}
				int_0[num4] += num3;
			}
		}
		private static void decode_10i40_35bits(short[] index, int indexOffset, int[] int_0)
		{
			GloabFunc.memsetInt(int_0, 0, 0, 160);
			for (int i = 0; i < 5; i++)
			{
				int num = (int)index[i + indexOffset];
				int num2 = num & 7;
				num2 = DefineConstants_Dec.dgray[num2];
				num2 *= 5;
				int num3 = num2 + i;
				int num4;
				if ((num >> 3 & 1) == 0)
				{
					num4 = 4096;
				}
				else
				{
					num4 = -4096;
				}
				num2 = (int)(index[i + indexOffset + 5] & 7);
				num2 = DefineConstants_Dec.dgray[num2];
				num2 *= 5;
				int num5 = num2 + i;
				int_0[num3] = num4;
				if (num5 < num3)
				{
					num4 = -num4;
				}
				int_0[num5] += num4;
			}
		}
		private static int gmed_n(int[] int_0, int indOffset, int int_1)
		{
			int[] array = new int[9];
			int[] array2 = new int[9];
			int num = 0;
			for (int i = 0; i < int_1; i++)
			{
				array2[i] = int_0[i + indOffset];
			}
			for (int i = 0; i < int_1; i++)
			{
				int num2 = -32767;
				for (int j = 0; j < int_1; j++)
				{
					if (array2[j] >= num2)
					{
						num2 = array2[j];
						num = j;
					}
				}
				array2[num] = -32768;
				array[i] = num;
			}
			int num3 = array[int_1 >> 1];
			return int_0[num3 + indOffset];
		}
		private static void ec_gain_pitch(GloabFunc_Dec.ec_gain_pitchState ec_gain_pitchState_0, short state, ref int gain_pitch)
		{
			int num = GloabFunc_Dec.gmed_n(ec_gain_pitchState_0.pbuf, 0, 5);
			if (num > ec_gain_pitchState_0.past_gain_pit)
			{
				num = ec_gain_pitchState_0.past_gain_pit;
			}
			gain_pitch = num * DefineConstants_Dec.pdown[(int)state] >> 15;
		}
		private static int d_gain_pitch(Mode mode, int index)
		{
			int result;
			if (mode == Mode.MR122)
			{
				result = DefineConstants_Dec.qua_gain_pitch[index] >> 2 << 2;
			}
			else
			{
				result = DefineConstants_Dec.qua_gain_pitch[index];
			}
			return result;
		}
		private static void ec_gain_pitch_update(GloabFunc_Dec.ec_gain_pitchState ec_gain_pitchState_0, int int_0, int prev_bf, ref int gain_pitch)
		{
			if (int_0 == 0)
			{
				if (prev_bf != 0 && gain_pitch > ec_gain_pitchState_0.prev_gp)
				{
					gain_pitch = ec_gain_pitchState_0.prev_gp;
				}
				ec_gain_pitchState_0.prev_gp = gain_pitch;
			}
			ec_gain_pitchState_0.past_gain_pit = gain_pitch;
			if (ec_gain_pitchState_0.past_gain_pit > 16384)
			{
				ec_gain_pitchState_0.past_gain_pit = 16384;
			}
			ec_gain_pitchState_0.pbuf[0] = ec_gain_pitchState_0.pbuf[1];
			ec_gain_pitchState_0.pbuf[1] = ec_gain_pitchState_0.pbuf[2];
			ec_gain_pitchState_0.pbuf[2] = ec_gain_pitchState_0.pbuf[3];
			ec_gain_pitchState_0.pbuf[3] = ec_gain_pitchState_0.pbuf[4];
			ec_gain_pitchState_0.pbuf[4] = ec_gain_pitchState_0.past_gain_pit;
		}
		private static void gc_pred(GloabFunc_Dec.gc_predState gc_predState_0, Mode mode, int[] code, int codeOffset, ref int exp_gcode0, ref int frac_gcode0, ref int exp_en, ref int frac_en)
		{
			int num = 0;
			for (int i = 0; i < 40; i++)
			{
				num += code[i + codeOffset] * code[i + codeOffset];
			}
			if (1073741823 <= num | num < 0)
			{
				num = 2147483647;
			}
			else
			{
				num <<= 1;
			}
			int num2;
			int num3;
			if (mode == Mode.MR122)
			{
				num = (num + 32768 >> 16) * 52428;
				num2 = 0;
				num3 = 0;
				GloabFunc_Dec.Log2(num, ref num2, ref num3);
				num = (num2 - 30 << 16) + (num3 << 1);
				int num4 = 0;
				for (int i = 0; i < 4; i++)
				{
					num4 += gc_predState_0.past_qua_en_MR122[i] * DefineConstants_Dec.pred_MR122[i];
				}
				num4 <<= 1;
				num4 += 783741;
				num4 = num4 - num >> 1;
				exp_gcode0 = num4 >> 16;
				frac_gcode0 = (num4 >> 1) - (exp_gcode0 << 15);
				return;
			}
			int num5 = 0;
			if (num != 0)
			{
				while ((num & 1073741824) == 0)
				{
					num5++;
					num <<= 1;
				}
			}
			num2 = 0;
			num3 = 0;
			GloabFunc_Dec.Log2_norm(num, num5, ref num2, ref num3);
			int num6 = num2 * -49320 + (num3 * -24660 >> 15 << 1);
			if (mode == Mode.MR102)
			{
				num6 += 2134784;
			}
			else
			{
				if (mode == Mode.MR795)
				{
					num6 += 2183936;
					frac_en = num >> 16;
					exp_en = -11 - num5;
				}
				else
				{
					if (mode == Mode.MR74)
					{
						num6 += 2085632;
					}
					else
					{
						if (mode == Mode.MR67)
						{
							num6 += 2065152;
						}
						else
						{
							num6 += 2134784;
						}
					}
				}
			}
			num6 <<= 9;
			for (int i = 0; i < 4; i++)
			{
				num6 += DefineConstants_Dec.pred[i] * gc_predState_0.past_qua_en[i];
			}
			int num7 = num6 >> 15;
			if (mode == Mode.MR74)
			{
				num6 = num7 * 10878;
			}
			else
			{
				num6 = num7 * 10886;
			}
			num6 >>= 9;
			exp_gcode0 = num6 >> 15;
			frac_gcode0 = num6 - exp_gcode0 * 32768;
		}
		private static void gc_pred_update(GloabFunc_Dec.gc_predState gc_predState_0, int qua_ener_MR122, int qua_ener)
		{
			for (int i = 3; i > 0; i--)
			{
				gc_predState_0.past_qua_en[i] = gc_predState_0.past_qua_en[i - 1];
				gc_predState_0.past_qua_en_MR122[i] = gc_predState_0.past_qua_en_MR122[i - 1];
			}
			gc_predState_0.past_qua_en_MR122[0] = qua_ener_MR122;
			gc_predState_0.past_qua_en[0] = qua_ener;
		}
		private static void Dec_gain(GloabFunc_Dec.gc_predState pred_state, Mode mode, int index, int[] code, int codeOffset, int evenSubfr, ref int gain_pit, ref int gain_cod)
		{
			int num = 0;
			int num2 = 0;
			index <<= 2;
			int[] array;
			int num3;
			int num4;
			int qua_ener_MR;
			int qua_ener;
			if (mode != Mode.MR102 && mode != Mode.MR74)
			{
				if (mode != Mode.MR67)
				{
					if (mode == Mode.MR475)
					{
						index += 1 - evenSubfr << 1;
						array = DefineConstants_Dec.table_gain_MR475;
						num3 = index;
						gain_pit = array[num3++];
						num4 = array[num3++];
						GloabFunc_Dec.Log2(num4, ref num2, ref num);
						num2 -= 12;
						int num5 = num >> 5;
						if ((num & 16) != 0)
						{
							num5++;
						}
						qua_ener_MR = num5 + (num2 << 10);
						num5 = num2 * 49320;
						num5 += num * 24660 >> 15 << 1;
						qua_ener = (num5 << 13) + 32768 >> 16;
						goto IL_F9;
					}
					array = DefineConstants_Dec.table_gain_lowrates;
					num3 = index;
					gain_pit = array[num3++];
					num4 = array[num3++];
					qua_ener_MR = array[num3++];
					qua_ener = array[num3];
					goto IL_F9;
				}
			}
			array = DefineConstants_Dec.table_gain_highrates;
			num3 = index;
			gain_pit = array[num3++];
			num4 = array[num3++];
			qua_ener_MR = array[num3++];
			qua_ener = array[num3];
			IL_F9:
			int num6 = 0;
			int num7 = 0;
			GloabFunc_Dec.gc_pred(pred_state, mode, code, codeOffset, ref num2, ref num, ref num6, ref num7);
			int num8 = GloabFunc_Dec.Pow2(14, num);
			if (num2 < 11)
			{
				gain_cod = num4 * num8 >> 25 - num2;
			}
			else
			{
				int num5 = num4 * num8 << num2 - 9;
				if (num5 >> num2 - 9 != num4 * num8)
				{
					gain_cod = 32767;
				}
				else
				{
					gain_cod = num5 >> 16;
				}
			}
			GloabFunc_Dec.gc_pred_update(pred_state, qua_ener_MR, qua_ener);
		}
		private static void gc_pred_average_limited(GloabFunc_Dec.gc_predState gc_predState_0, ref int ener_avg_MR122, ref int ener_avg)
		{
			int num = 0;
			for (int i = 0; i < 4; i++)
			{
				num += gc_predState_0.past_qua_en_MR122[i];
			}
			num = num * 8192 >> 15;
			if (num < -2381)
			{
				num = -2381;
			}
			ener_avg_MR122 = (int)((short)num);
			num = 0;
			for (int i = 0; i < 4; i++)
			{
				num += gc_predState_0.past_qua_en[i];
				if (num < -32768)
				{
					num = -32768;
				}
				else
				{
					if (num > 32767)
					{
						num = 32767;
					}
				}
			}
			num = num * 8192 >> 15;
			ener_avg = num;
		}
		private static void ec_gain_code(GloabFunc_Dec.ec_gain_codeState ec_gain_codeState_0, GloabFunc_Dec.gc_predState pred_state, short state, ref int gain_code)
		{
			int qua_ener_MR = 0;
			int qua_ener = 0;
			int num = GloabFunc_Dec.gmed_n(ec_gain_codeState_0.gbuf, 0, 5);
			if (num > ec_gain_codeState_0.past_gain_code)
			{
				num = ec_gain_codeState_0.past_gain_code;
			}
			num = num * DefineConstants_Dec.cdown[(int)state] >> 15;
			gain_code = num;
			GloabFunc_Dec.gc_pred_average_limited(pred_state, ref qua_ener_MR, ref qua_ener);
			GloabFunc_Dec.gc_pred_update(pred_state, qua_ener_MR, qua_ener);
		}
		private static void ec_gain_code_update(GloabFunc_Dec.ec_gain_codeState ec_gain_codeState_0, short short_0, short prev_bf, ref int gain_code)
		{
			if (short_0 == 0)
			{
				if (prev_bf != 0 && gain_code > ec_gain_codeState_0.prev_gc)
				{
					gain_code = ec_gain_codeState_0.prev_gc;
				}
				ec_gain_codeState_0.prev_gc = gain_code;
			}
			ec_gain_codeState_0.past_gain_code = gain_code;
			ec_gain_codeState_0.gbuf[0] = ec_gain_codeState_0.gbuf[1];
			ec_gain_codeState_0.gbuf[1] = ec_gain_codeState_0.gbuf[2];
			ec_gain_codeState_0.gbuf[2] = ec_gain_codeState_0.gbuf[3];
			ec_gain_codeState_0.gbuf[3] = ec_gain_codeState_0.gbuf[4];
			ec_gain_codeState_0.gbuf[4] = gain_code;
		}
		private static void d_gain_code(GloabFunc_Dec.gc_predState pred_state, Mode mode, int index, int[] code, int codeOffset, ref int gain_code)
		{
			int num = 0;
			int fraction = 0;
			int num2 = 0;
			int num3 = 0;
			GloabFunc_Dec.gc_pred(pred_state, mode, code, codeOffset, ref num, ref fraction, ref num2, ref num3);
			int[] qua_gain_code = DefineConstants_Dec.qua_gain_code;
			int num4 = index + index + index;
			if (mode == Mode.MR122)
			{
				int num5 = GloabFunc_Dec.Pow2(num, fraction);
				if (num5 <= 2047)
				{
					num5 <<= 4;
				}
				else
				{
					num5 = 32767;
				}
				gain_code = num5 * qua_gain_code[num4++] >> 15 << 1;
				if (((long)gain_code & (long)((ulong)-32768)) != 0L)
				{
					gain_code = 32767;
				}
			}
			else
			{
				int num5 = GloabFunc_Dec.Pow2(14, fraction);
				int num6 = qua_gain_code[num4++] * num5 << 1;
				num = 9 - num;
				if (num > 0)
				{
					num6 >>= num;
				}
				else
				{
					for (int i = num; i < 0; i++)
					{
						int num7 = num6 << 1;
						if (((long)(num6 ^ num7) & (long)((ulong)-2147483648)) != 0L)
						{
							num6 = ((((long)num6 & (long)((ulong)-2147483648)) != 0L) ? -2147483648 : 2147483647);
							break;
						}
						num6 = num7;
					}
				}
				gain_code = num6 >> 16;
				if (((long)gain_code & (long)((ulong)-32768)) != 0L)
				{
					gain_code = 32767;
				}
			}
			int qua_ener_MR = qua_gain_code[num4];
			num4++;
			int qua_ener = qua_gain_code[num4];
			num4++;
			GloabFunc_Dec.gc_pred_update(pred_state, qua_ener_MR, qua_ener);
		}
		private static void Int_lsf(int[] lsf_old, int[] lsf_new, int i_subfr, int[] lsf_out)
		{
			if (i_subfr <= 40)
			{
				if (i_subfr == 0)
				{
					for (int i = 0; i < 10; i++)
					{
						lsf_out[i] = lsf_old[i] - (lsf_old[i] >> 2) + (lsf_new[i] >> 2);
					}
					return;
				}
				if (i_subfr != 40)
				{
					return;
				}
				for (int i = 0; i < 10; i++)
				{
					lsf_out[i] = (lsf_old[i] >> 1) + (lsf_new[i] >> 1);
				}
				return;
			}
			else
			{
				if (i_subfr == 80)
				{
					for (int i = 0; i < 10; i++)
					{
						lsf_out[i] = (lsf_old[i] >> 2) - (lsf_new[i] >> 2) + lsf_new[i];
					}
					return;
				}
				if (i_subfr != 120)
				{
					return;
				}
				GloabFunc.memcpyInt(lsf_out, 0, lsf_new, 0, 10);
				return;
			}
		}
		private static int Cb_gain_average(GloabFunc_Dec.Cb_gain_averageState cb_gain_averageState_0, Mode mode, int gain_code, int[] int_0, int[] lspAver, short short_0, short prev_bf, short pdfi, short prev_pdf, int inBackgroundNoise, int voicedHangover)
		{
			int[] array = new int[10];
			int num = gain_code;
			cb_gain_averageState_0.cbGainHistory[0] = cb_gain_averageState_0.cbGainHistory[1];
			cb_gain_averageState_0.cbGainHistory[1] = cb_gain_averageState_0.cbGainHistory[2];
			cb_gain_averageState_0.cbGainHistory[2] = cb_gain_averageState_0.cbGainHistory[3];
			cb_gain_averageState_0.cbGainHistory[3] = cb_gain_averageState_0.cbGainHistory[4];
			cb_gain_averageState_0.cbGainHistory[4] = cb_gain_averageState_0.cbGainHistory[5];
			cb_gain_averageState_0.cbGainHistory[5] = cb_gain_averageState_0.cbGainHistory[6];
			cb_gain_averageState_0.cbGainHistory[6] = gain_code;
			for (int i = 0; i < 10; i++)
			{
				int num2 = Math.Abs(lspAver[i] - int_0[i]);
				int num3 = 0;
				if (num2 != 0)
				{
					while ((num2 & 8192) == 0)
					{
						num3++;
						num2 <<= 1;
					}
				}
				int num4 = lspAver[i];
				int num5 = 0;
				if (num4 != 0)
				{
					while ((num4 & 16384) == 0)
					{
						num5++;
						num4 <<= 1;
					}
				}
				array[i] = (num2 << 15) / num4;
				int num6 = 2 + num3 - num5;
				if (num6 >= 0)
				{
					array[i] >>= num6;
				}
				else
				{
					array[i] <<= -num6;
				}
			}
			int num7 = array[0] + array[1] + array[2] + array[3] + array[4] + array[5] + array[6] + array[7] + array[8] + array[9];
			if (num7 > 32767)
			{
				num7 = 32767;
			}
			cb_gain_averageState_0.hangVar += 1;
			if (num7 <= 5325)
			{
				cb_gain_averageState_0.hangVar = 0;
			}
			if (cb_gain_averageState_0.hangVar > 10)
			{
				cb_gain_averageState_0.hangCount = 0;
			}
			int num8 = 8192;
			if (mode <= Mode.MR67 | mode == Mode.MR102)
			{
				if (cb_gain_averageState_0.hangCount >= 40 & num7 <= 5325)
				{
					if (((pdfi != 0 & prev_pdf != 0) | short_0 != 0 | prev_bf != 0) & voicedHangover > 1 & inBackgroundNoise != 0 & mode < Mode.MR67)
					{
						int num9 = num7 - 4506;
						int num2 = 0;
						if (num9 > 0)
						{
							num2 = num9;
						}
						if (2048 >= num2)
						{
							num8 = num2 << 2;
						}
					}
					else
					{
						int num9 = num7 - 3277;
						int num2 = 0;
						if (num9 > 0)
						{
							num2 = num9;
						}
						if (2048 >= num2)
						{
							num8 = num2 << 2;
						}
					}
				}
				int num10 = cb_gain_averageState_0.cbGainHistory[2] + cb_gain_averageState_0.cbGainHistory[3] + cb_gain_averageState_0.cbGainHistory[4] + cb_gain_averageState_0.cbGainHistory[5] + cb_gain_averageState_0.cbGainHistory[6];
				int num11;
				if (num10 > 163822)
				{
					num11 = 32767;
				}
				else
				{
					num11 = 3277 * num10 + 8192 >> 14;
				}
				if ((short_0 != 0 | prev_bf != 0) & inBackgroundNoise != 0 & mode < Mode.MR67)
				{
					num10 = 9362 * (cb_gain_averageState_0.cbGainHistory[0] + cb_gain_averageState_0.cbGainHistory[1] + cb_gain_averageState_0.cbGainHistory[2] + cb_gain_averageState_0.cbGainHistory[3] + cb_gain_averageState_0.cbGainHistory[4] + cb_gain_averageState_0.cbGainHistory[5] + cb_gain_averageState_0.cbGainHistory[6]);
					num11 = num10 + 32768 >> 16;
				}
				num10 = num8 * num;
				num10 += num11 << 13;
				num10 -= num8 * num11;
				num = num10 + 4096 >> 13;
			}
			cb_gain_averageState_0.hangCount++;
			if (((long)cb_gain_averageState_0.hangCount & (long)((ulong)-2147483648)) != 0L)
			{
				cb_gain_averageState_0.hangCount = 40;
			}
			return num;
		}
		private static void ph_disp(GloabFunc_Dec.ph_dispState state, Mode mode, int[] int_0, int xOffsest, int cbGain, int ltpGain, int[] inno, int innoOffset, int pitch_fac, int tmp_shift)
		{
			int[] array = new int[40];
			int[] array2 = new int[40];
			state.gainMem[4] = state.gainMem[3];
			state.gainMem[3] = state.gainMem[2];
			state.gainMem[2] = state.gainMem[1];
			state.gainMem[1] = state.gainMem[0];
			state.gainMem[0] = ltpGain;
			int num = 2;
			if (ltpGain < 14746)
			{
				num = 0;
				if (ltpGain > 9830)
				{
					num = 1;
				}
			}
			int num2 = state.prevCbGain * 16384 + 4096 >> 13;
			if (cbGain > num2)
			{
				state.onset = 2;
			}
			else
			{
				if (state.onset > 0)
				{
					state.onset--;
				}
			}
			if (state.onset == 0)
			{
				int num3 = 0;
				for (int i = 0; i < 5; i++)
				{
					if (state.gainMem[i] < 9830)
					{
						num3++;
					}
				}
				if (num3 > 2)
				{
					num = 0;
				}
			}
			if (num > state.prevState + 1 & state.onset == 0)
			{
				num--;
			}
			if (num < 2 & state.onset > 0)
			{
				num++;
			}
			if (cbGain < 10)
			{
				num = 2;
			}
			if (state.lockFull == 1)
			{
				num = 0;
			}
			state.prevState = num;
			state.prevCbGain = cbGain;
			if (mode != Mode.MR122 & mode != Mode.MR102 & mode != Mode.MR74 & num < 2)
			{
				int num4 = 0;
				for (int i = 0; i < 40; i++)
				{
					if (inno[innoOffset + i] != 0)
					{
						array2[num4] = i;
						num4++;
					}
				}
				GloabFunc.memcpyInt(array, 0, inno, innoOffset, 40);
				GloabFunc.memsetInt(inno, innoOffset, 0, 160);
				int[] array3 = DefineConstants_Dec.ph_imp_mid;
				if (num == 0)
				{
					array3 = DefineConstants_Dec.ph_imp_low;
				}
				if (mode == Mode.MR795)
				{
					array3 = DefineConstants_Dec.ph_imp_mid_MR795;
					if (num == 0)
					{
						array3 = DefineConstants_Dec.ph_imp_low_MR795;
					}
				}
				for (int j = 0; j < num4; j++)
				{
					int num5 = array2[j];
					int num6 = 0;
					for (int i = num5; i < 40; i++)
					{
						num2 = array[num5] * array3[num6++] >> 15;
						inno[innoOffset + i] = inno[innoOffset + i] + num2;
					}
					for (int i = 0; i < num5; i++)
					{
						num2 = array[num5] * array3[num6++] >> 15;
						inno[innoOffset + i] = inno[innoOffset + i] + num2;
					}
				}
			}
			for (int i = 0; i < 40; i++)
			{
				num2 = int_0[xOffsest + i] * pitch_fac + inno[innoOffset + i] * cbGain;
				int num7 = num2 << tmp_shift;
				int_0[xOffsest + i] = num7 + 16384 >> 15;
				if (Math.Abs(int_0[xOffsest + i]) > 32767)
				{
					if (((long)(num2 ^ num7) & (long)((ulong)-2147483648)) != 0L)
					{
						int_0[xOffsest + i] = ((((long)num2 & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
					}
					else
					{
						int_0[xOffsest + i] = ((((long)num7 & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
					}
				}
			}
		}
		private static int sqrt_l_exp(int int_0, ref int int_1)
		{
			if (int_0 <= 0)
			{
				int_1 = 0;
				return 0;
			}
			int num = 0;
			int num2;
			if (int_0 != 0)
			{
				num2 = int_0;
				while ((num2 & 1073741824) == 0)
				{
					num++;
					num2 <<= 1;
				}
			}
			num &= 65534;
			int_0 <<= num;
			int_1 = (int)((short)num);
			int_0 >>= 9;
			int num3 = (int)((short)(int_0 >> 16));
			int_0 >>= 1;
			int num4 = int_0 & 32767;
			num3 -= 16;
			int num5 = DefineConstants_Dec.sqrt_table[num3] << 16;
			num2 = DefineConstants_Dec.sqrt_table[num3] - DefineConstants_Dec.sqrt_table[num3 + 1];
			return num5 - (num2 * num4 << 1);
		}
		private static short Ex_ctrl(int[] excitation, int excEnergy, int[] exEnergyHist, int voicedHangover, short prevBFI, short carefulFlag)
		{
			int num = GloabFunc_Dec.gmed_n(exEnergyHist, 0, 9);
			int num2 = exEnergyHist[7] + exEnergyHist[8] >> 1;
			if (exEnergyHist[8] < num2)
			{
				num2 = exEnergyHist[8];
			}
			if (excEnergy < num & excEnergy > 5)
			{
				int num3 = num2 << 2;
				if (voicedHangover < 7 || prevBFI != 0)
				{
					num3 -= num2;
				}
				if (num > num3)
				{
					num = num3;
				}
				int num4 = 0;
				if (excEnergy != 0)
				{
					while ((excEnergy & 16384) == 0)
					{
						num4++;
						excEnergy <<= 1;
					}
				}
				excEnergy = 536838144 / excEnergy;
				int num5 = num * excEnergy << 1;
				num5 >>= 20 - num4;
				if (num5 > 32767)
				{
					num5 = 32767;
				}
				int num6 = num5;
				if (carefulFlag != 0 & num6 > 3072)
				{
					num6 = 3072;
				}
				for (int i = 0; i < 40; i++)
				{
					num5 = num6 * excitation[i] << 1;
					num5 >>= 11;
					excitation[i] = num5;
				}
			}
			return 0;
		}
		private static int Inv_sqrt(int int_0)
		{
			if (int_0 <= 0)
			{
				return 1073741823;
			}
			int num = 0;
			while ((int_0 & 1073741824) == 0)
			{
				num++;
				int_0 <<= 1;
			}
			num = 30 - num;
			if ((num & 1) == 0)
			{
				int_0 >>= 1;
			}
			num >>= 1;
			num++;
			int_0 >>= 9;
			int num2 = (int)((short)(int_0 >> 16));
			int_0 >>= 1;
			int num3 = int_0 & 32767;
			num2 -= 16;
			int num4 = DefineConstants_Dec.inv_sqrt_table[num2] << 16;
			int num5 = DefineConstants_Dec.inv_sqrt_table[num2] - DefineConstants_Dec.inv_sqrt_table[num2 + 1];
			num4 -= num5 * num3 << 1;
			return num4 >> num;
		}
		private static int energy_old(int[] int_0, int innOffset)
		{
			int num = 0;
			for (int i = 0; i < 40; i += 8)
			{
				int num2 = int_0[innOffset + i] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 1] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 2] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 3] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 4] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 5] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 6] >> 2;
				num += num2 * num2;
				num2 = int_0[innOffset + i + 7] >> 2;
				num += num2 * num2;
			}
			if (((long)num & (long)((ulong)-1073741824)) != 0L)
			{
				return 2147483647;
			}
			return num << 1;
		}
		private static int energy_new(int[] int_0, int innOffset)
		{
			int num = 0;
			int num2 = 0 + int_0[innOffset] * int_0[innOffset];
			for (int i = 1; i < 40; i += 3)
			{
				num2 += int_0[innOffset + i] * int_0[innOffset + i];
				num2 += int_0[innOffset + i + 1] * int_0[innOffset + i + 1];
				num2 += int_0[innOffset + i + 2] * int_0[innOffset + i + 2];
				if (((long)num2 & (long)((ulong)-1073741824)) != 0L)
				{
					num = 1;
					IL_60:
					if (num != 0)
					{
						num2 = GloabFunc_Dec.energy_old(int_0, innOffset);
					}
					else
					{
						num2 >>= 3;
					}
					return num2;
				}
			}
			goto IL_60;
		}
		private static void agc2(int[] sig_in, int sig_inOffset, int[] sig_out, int sig_outOffset)
		{
			int num = GloabFunc_Dec.energy_new(sig_out, sig_outOffset);
			if (num == 0)
			{
				return;
			}
			int num2 = 0;
			while ((num & 536870912) == 0)
			{
				num2++;
				num <<= 1;
			}
			short num3 = (short)((long)num + 32768L >> 16);
			num = GloabFunc_Dec.energy_new(sig_in, sig_inOffset);
			short num4;
			if (num == 0)
			{
				num4 = 0;
			}
			else
			{
				int i = 0;
				while ((num & 1073741824) == 0)
				{
					i++;
					num <<= 1;
				}
				short num5;
				if (num < 2147450879)
				{
					num5 = (short)((long)num + 32768L >> 16);
				}
				else
				{
					num5 = 32767;
				}
				num2 -= i;
				num = ((int)num3 << 15) / (int)num5;
				num <<= 7;
				if (num2 > 0)
				{
					num >>= num2;
				}
				else
				{
					num <<= -num2;
				}
				num = GloabFunc_Dec.Inv_sqrt(num);
				num4 = (short)((long)((long)num << 9) + 32768L >> 16);
			}
			for (int i = 0; i < 40; i++)
			{
				sig_out[i + sig_outOffset] = sig_out[i + sig_outOffset] * (int)num4 >> 12;
			}
		}
		private static short Bgn_scd(GloabFunc_Dec.Bgn_scdState bgn_scdState_0, int[] ltpGainHist, int[] speech, int speechOffset, ref int voicedHangover)
		{
			int num = 0;
			for (int i = 0; i < 160; i++)
			{
				num += speech[i + speechOffset] * speech[i + speechOffset];
			}
			int num2;
			if (num < 268435455 & num >= 0)
			{
				num2 = num >> 13;
			}
			else
			{
				num2 = 32767;
			}
			int num3 = 32767;
			for (int i = 0; i < 60; i++)
			{
				if (bgn_scdState_0.frameEnergyHist[i] < num3)
				{
					num3 = bgn_scdState_0.frameEnergyHist[i];
				}
			}
			int num4 = num3 << 4;
			int num5 = bgn_scdState_0.frameEnergyHist[0];
			for (int i = 1; i < 56; i++)
			{
				if (num5 < bgn_scdState_0.frameEnergyHist[i])
				{
					num5 = bgn_scdState_0.frameEnergyHist[i];
				}
			}
			int num6 = bgn_scdState_0.frameEnergyHist[40];
			for (int i = 41; i < 60; i++)
			{
				if (num6 < bgn_scdState_0.frameEnergyHist[i])
				{
					num6 = bgn_scdState_0.frameEnergyHist[i];
				}
			}
			short result = 0;
			if (num5 > 20 & num2 < 17578 & num2 > 20 & (num2 < num4 || num6 < 1953))
			{
				if (bgn_scdState_0.bgHangover + 1 > 30)
				{
					bgn_scdState_0.bgHangover = 30;
				}
				else
				{
					bgn_scdState_0.bgHangover += 1;
				}
			}
			else
			{
				bgn_scdState_0.bgHangover = 0;
			}
			if (bgn_scdState_0.bgHangover > 1)
			{
				result = 1;
			}
			for (int i = 0; i < 59; i++)
			{
				bgn_scdState_0.frameEnergyHist[i] = bgn_scdState_0.frameEnergyHist[i + 1];
			}
			bgn_scdState_0.frameEnergyHist[59] = num2;
			int num7 = 13926;
			if (bgn_scdState_0.bgHangover > 8)
			{
				num7 = 15565;
			}
			if (bgn_scdState_0.bgHangover > 15)
			{
				num7 = 16383;
			}
			short num8 = 0;
			if (GloabFunc_Dec.gmed_n(ltpGainHist, 4, 5) > num7)
			{
				num8 = 1;
			}
			if (bgn_scdState_0.bgHangover > 20)
			{
				if (GloabFunc_Dec.gmed_n(ltpGainHist, 0, 9) > num7)
				{
					num8 = 1;
				}
				else
				{
					num8 = 0;
				}
			}
			if (num8 != 0)
			{
				voicedHangover = 0;
			}
			else
			{
				int num9 = voicedHangover + 1;
				if (num9 > 10)
				{
					voicedHangover = 10;
				}
				else
				{
					voicedHangover = num9;
				}
			}
			return result;
		}
		private static void dtx_dec_activity_update(GloabFunc_Dec.dtx_decState dtx_decState_0, int[] int_0, int[] frame, int frameOffset)
		{
			dtx_decState_0.lsf_hist_ptr += 10;
			if (dtx_decState_0.lsf_hist_ptr == 80)
			{
				dtx_decState_0.lsf_hist_ptr = 0;
			}
			GloabFunc.memcpyInt(dtx_decState_0.lsf_hist, (int)dtx_decState_0.lsf_hist_ptr, int_0, 0, 10);
			int num = 0;
			for (int i = 0; i < 160; i++)
			{
				num += frame[i + frameOffset] * frame[i + frameOffset];
				if (((long)num & (long)((ulong)-2147483648)) != 0L)
				{
					break;
				}
			}
			int num2 = (((long)num & (long)((ulong)-1073741824)) != 0L) ? 2147483646 : (num << 1);
			int num3 = 0;
			int num4 = 0;
			GloabFunc_Dec.Log2(num2, ref num3, ref num4);
			num2 = num3 << 10;
			num2 += num4 >> 5;
			num2 -= 8521;
			dtx_decState_0.log_en_hist_ptr += 1;
			if (dtx_decState_0.log_en_hist_ptr == 8)
			{
				dtx_decState_0.log_en_hist_ptr = 0;
			}
			dtx_decState_0.log_en_hist[(int)dtx_decState_0.log_en_hist_ptr] = num2;
		}
		private static void Decoder_amr(GloabFunc_Dec.Decoder_amrState decoder_amrState_0, Mode mode, short[] parm, int parmOffset, RXFrameType frame_type, int[] synth, int synthOffset, int[] A_t, int A_tOffset)
		{
			int[] array = new int[10];
			int num = 0;
			int[] array2 = new int[10];
			int lsp_midOffset = 0;
			int[] array3 = new int[10];
			int dstoffset = 0;
			int[] array4 = new int[10];
			int[] array5 = new int[40];
			int num2 = 0;
			int[] array6 = new int[40];
			int num3 = 0;
			int[] array7 = new int[40];
			int num4 = 0;
			int frac = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int index = 0;
			short num9 = 0;
			short num10 = 0;
			GloabFunc_Dec.DTXStateType dTXStateType = GloabFunc_Dec.rx_dtx_handler(decoder_amrState_0.dtxDecoderState, frame_type);
			if (dTXStateType != GloabFunc_Dec.DTXStateType.SPEECH)
			{
				GloabFunc_Dec.Decoder_amr_reset(decoder_amrState_0, Mode.MRDTX);
				GloabFunc_Dec.dtx_dec(decoder_amrState_0.dtxDecoderState, decoder_amrState_0.mem_syn, decoder_amrState_0.mem_synOffset, decoder_amrState_0.lsfState, decoder_amrState_0.pred_state, decoder_amrState_0.Cb_gain_averState, dTXStateType, mode, parm, parmOffset, synth, synthOffset, A_t, A_tOffset);
				GloabFunc_Dec.Lsf_lsp(decoder_amrState_0.lsfState.past_lsf_q, decoder_amrState_0.lsp_old);
				GloabFunc_Dec.lsp_avg(decoder_amrState_0.lsp_avg_st, decoder_amrState_0.lsfState.past_lsf_q, 0);
			}
			else
			{
				if (DefineConstants_Dec.table_speech_bad[(int)frame_type] != 0)
				{
					num9 = 1;
					if (frame_type != RXFrameType.RX_SPEECH_BAD)
					{
						GloabFunc_Dec.Build_CN_param(ref decoder_amrState_0.nodataSeed, mode, parm, parmOffset);
					}
				}
				else
				{
					if (frame_type == RXFrameType.RX_SPEECH_DEGRADED)
					{
						num10 = 1;
					}
				}
				if (num9 != 0)
				{
					decoder_amrState_0.state += 1;
				}
				else
				{
					if (decoder_amrState_0.state == 6)
					{
						decoder_amrState_0.state = 5;
					}
					else
					{
						decoder_amrState_0.state = 0;
					}
				}
				if (decoder_amrState_0.state > 6)
				{
					decoder_amrState_0.state = 6;
				}
				if (decoder_amrState_0.dtxDecoderState.dtxGlobalState == GloabFunc_Dec.DTXStateType.DTX)
				{
					decoder_amrState_0.state = 5;
					decoder_amrState_0.prev_bf = 0;
				}
				else
				{
					if (decoder_amrState_0.dtxDecoderState.dtxGlobalState == GloabFunc_Dec.DTXStateType.DTX_MUTE)
					{
						decoder_amrState_0.state = 5;
						decoder_amrState_0.prev_bf = 1;
					}
				}
				GloabFunc.memcpyInt(array3, dstoffset, decoder_amrState_0.lsfState.past_lsf_q, 0, 10);
				if (mode != Mode.MR122)
				{
					GloabFunc_Dec.D_plsf_3(decoder_amrState_0.lsfState, mode, num9, parm, parmOffset, array, num);
					parmOffset += 3;
					GloabFunc_Dec.Int_lpc_1to3(decoder_amrState_0.lsp_old, 0, array, num, A_t, A_tOffset);
				}
				else
				{
					GloabFunc_Dec.D_plsf_5(decoder_amrState_0.lsfState, num9, parm, parmOffset, array2, array);
					parmOffset += 5;
					GloabFunc_Dec.Int_lpc_1and3(decoder_amrState_0.lsp_old, 0, array2, lsp_midOffset, array, num, A_t, A_tOffset);
				}
				GloabFunc.memcpyInt(decoder_amrState_0.lsp_old, 0, array, num, 10);
				int num11 = A_tOffset;
				int num12 = 0;
				int num13 = -1;
				int i = 0;
				while (i < 160)
				{
					num13++;
					num12 = 1 - num12;
					int num14 = i;
					if (i == 80 && (mode != Mode.MR475 & mode != Mode.MR515))
					{
						num14 = 0;
					}
					int num15 = (int)parm[parmOffset];
					parmOffset++;
					if (mode != Mode.MR122)
					{
						short flag = 0;
						if (mode == Mode.MR475 || mode == Mode.MR515 || mode == Mode.MR59 || mode == Mode.MR67)
						{
							flag = 1;
						}
						short num16 = 5;
						short num17 = 9;
						if (mode == Mode.MR795)
						{
							num16 = 10;
							num17 = 19;
						}
						int num18 = decoder_amrState_0.old_T0 - (int)num16;
						if (num18 < 20)
						{
							num18 = 20;
						}
						int num19 = num18 + (int)num17;
						if (num19 > 143)
						{
							num19 = 143;
							num18 = (int)(143 - num17);
						}
						GloabFunc_Dec.Dec_lag3(num15, num18, num19, num14, decoder_amrState_0.old_T0, ref num8, ref frac, (int)flag);
						decoder_amrState_0.T0_lagBuff = num8;
						if (num9 != 0)
						{
							if (decoder_amrState_0.old_T0 < 143)
							{
								decoder_amrState_0.old_T0++;
							}
							num8 = decoder_amrState_0.old_T0;
							frac = 0;
							if (decoder_amrState_0.inBackgroundNoise != 0 & decoder_amrState_0.voicedHangover > 4 & (mode == Mode.MR475 || mode == Mode.MR515 || mode == Mode.MR59))
							{
								num8 = decoder_amrState_0.T0_lagBuff;
							}
						}
						GloabFunc_Dec.Pred_lt_3or6_40(decoder_amrState_0.int_0, decoder_amrState_0.excOffset, num8, frac, 1);
					}
					else
					{
						GloabFunc_Dec.Dec_lag6(num15, 18, 143, num14, ref num8, ref frac);
						if (num9 != 0 || (num14 != 0 & num15 > 60))
						{
							decoder_amrState_0.T0_lagBuff = num8;
							num8 = decoder_amrState_0.old_T0;
							frac = 0;
						}
						GloabFunc_Dec.Pred_lt_3or6_40(decoder_amrState_0.int_0, decoder_amrState_0.excOffset, num8, frac, 0);
					}
					if (mode == Mode.MR475)
					{
						goto IL_4DB;
					}
					if (mode == Mode.MR515)
					{
						goto IL_4DB;
					}
					int j;
					int num20;
					if (mode == Mode.MR59)
					{
						num15 = (int)parm[parmOffset];
						parmOffset++;
						j = (int)parm[parmOffset];
						parmOffset++;
						GloabFunc_Dec.decode_2i40_11bits(j, num15, array5);
						num20 = decoder_amrState_0.sharp << 1;
					}
					else
					{
						if (mode == Mode.MR67)
						{
							num15 = (int)parm[parmOffset];
							parmOffset++;
							j = (int)parm[parmOffset];
							parmOffset++;
							GloabFunc_Dec.decode_3i40_14bits(j, num15, array5);
							num20 = decoder_amrState_0.sharp << 1;
						}
						else
						{
							if (mode <= Mode.MR795)
							{
								num15 = (int)parm[parmOffset];
								parmOffset++;
								j = (int)parm[parmOffset];
								parmOffset++;
								GloabFunc_Dec.decode_4i40_17bits(j, num15, array5);
								num20 = decoder_amrState_0.sharp << 1;
							}
							else
							{
								if (mode == Mode.MR102)
								{
									GloabFunc_Dec.decode_8i40_31bits(parm, parmOffset, array5);
									parmOffset += 7;
									num20 = decoder_amrState_0.sharp << 1;
								}
								else
								{
									num15 = (int)parm[parmOffset];
									parmOffset++;
									if (num9 != 0)
									{
										GloabFunc_Dec.ec_gain_pitch(decoder_amrState_0.ec_gain_p_st, decoder_amrState_0.state, ref num7);
									}
									else
									{
										num7 = GloabFunc_Dec.d_gain_pitch(mode, num15);
									}
									GloabFunc_Dec.ec_gain_pitch_update(decoder_amrState_0.ec_gain_p_st, (int)num9, (int)decoder_amrState_0.prev_bf, ref num7);
									GloabFunc_Dec.decode_10i40_35bits(parm, parmOffset, array5);
									parmOffset += 10;
									num20 = num7;
									if (num20 > 16383)
									{
										num20 = 32767;
									}
									else
									{
										num20 *= 2;
									}
								}
							}
						}
					}
					IL_506:
					for (j = num8; j < 40; j++)
					{
						num5 = array5[num2 + j - num8] * num20 >> 15;
						array5[num2 + j] = array5[num2 + j] + num5;
					}
					if (mode == Mode.MR475)
					{
						if (num12 != 0)
						{
							index = (int)parm[parmOffset];
							parmOffset++;
						}
						if (num9 == 0)
						{
							GloabFunc_Dec.Dec_gain(decoder_amrState_0.pred_state, mode, index, array5, num2, num12, ref num7, ref num6);
						}
						else
						{
							GloabFunc_Dec.ec_gain_pitch(decoder_amrState_0.ec_gain_p_st, decoder_amrState_0.state, ref num7);
							GloabFunc_Dec.ec_gain_code(decoder_amrState_0.ec_gain_c_st, decoder_amrState_0.pred_state, decoder_amrState_0.state, ref num6);
						}
						GloabFunc_Dec.ec_gain_pitch_update(decoder_amrState_0.ec_gain_p_st, (int)num9, (int)decoder_amrState_0.prev_bf, ref num7);
						GloabFunc_Dec.ec_gain_code_update(decoder_amrState_0.ec_gain_c_st, num9, decoder_amrState_0.prev_bf, ref num6);
						num20 = num7;
						if (num20 > 13017)
						{
							num20 = 13017;
						}
					}
					else
					{
						if (mode > Mode.MR74)
						{
							if (mode != Mode.MR102)
							{
								num15 = (int)parm[parmOffset];
								parmOffset++;
								if (mode != Mode.MR795)
								{
									if (num9 == 0)
									{
										GloabFunc_Dec.d_gain_code(decoder_amrState_0.pred_state, mode, num15, array5, num2, ref num6);
									}
									else
									{
										GloabFunc_Dec.ec_gain_code(decoder_amrState_0.ec_gain_c_st, decoder_amrState_0.pred_state, decoder_amrState_0.state, ref num6);
									}
									GloabFunc_Dec.ec_gain_code_update(decoder_amrState_0.ec_gain_c_st, num9, decoder_amrState_0.prev_bf, ref num6);
									num20 = num7;
									goto IL_7A0;
								}
								if (num9 != 0)
								{
									GloabFunc_Dec.ec_gain_pitch(decoder_amrState_0.ec_gain_p_st, decoder_amrState_0.state, ref num7);
								}
								else
								{
									num7 = GloabFunc_Dec.d_gain_pitch(mode, num15);
								}
								GloabFunc_Dec.ec_gain_pitch_update(decoder_amrState_0.ec_gain_p_st, (int)num9, (int)decoder_amrState_0.prev_bf, ref num7);
								num15 = (int)parm[parmOffset];
								parmOffset++;
								if (num9 == 0)
								{
									GloabFunc_Dec.d_gain_code(decoder_amrState_0.pred_state, mode, num15, array5, num2, ref num6);
								}
								else
								{
									GloabFunc_Dec.ec_gain_code(decoder_amrState_0.ec_gain_c_st, decoder_amrState_0.pred_state, decoder_amrState_0.state, ref num6);
								}
								GloabFunc_Dec.ec_gain_code_update(decoder_amrState_0.ec_gain_c_st, num9, decoder_amrState_0.prev_bf, ref num6);
								num20 = num7;
								if (num20 > 13017)
								{
									num20 = 13017;
									goto IL_7A0;
								}
								goto IL_7A0;
							}
						}
						num15 = (int)parm[parmOffset];
						parmOffset++;
						if (num9 == 0)
						{
							GloabFunc_Dec.Dec_gain(decoder_amrState_0.pred_state, mode, num15, array5, num2, num12, ref num7, ref num6);
						}
						else
						{
							GloabFunc_Dec.ec_gain_pitch(decoder_amrState_0.ec_gain_p_st, decoder_amrState_0.state, ref num7);
							GloabFunc_Dec.ec_gain_code(decoder_amrState_0.ec_gain_c_st, decoder_amrState_0.pred_state, decoder_amrState_0.state, ref num6);
						}
						GloabFunc_Dec.ec_gain_pitch_update(decoder_amrState_0.ec_gain_p_st, (int)num9, (int)decoder_amrState_0.prev_bf, ref num7);
						GloabFunc_Dec.ec_gain_code_update(decoder_amrState_0.ec_gain_c_st, num9, decoder_amrState_0.prev_bf, ref num6);
						num20 = num7;
						if (num20 > 13017)
						{
							num20 = 13017;
						}
						if (mode == Mode.MR102 && decoder_amrState_0.old_T0 > 45)
						{
							num20 >>= 2;
						}
					}
					IL_7A0:
					if (mode != Mode.MR475 || num12 == 0)
					{
						decoder_amrState_0.sharp = num7;
						if (decoder_amrState_0.sharp > 13017)
						{
							decoder_amrState_0.sharp = 13017;
						}
					}
					if (num20 > 16383)
					{
						num20 = 32767;
					}
					else
					{
						num20 *= 2;
					}
					long num21;
					if (num20 > 16384)
					{
						for (j = 0; j < 40; j++)
						{
							num5 = decoder_amrState_0.int_0[decoder_amrState_0.excOffset + j] * num20 >> 15;
							num21 = (long)((long)(num5 * num7) << 1);
							if (mode == Mode.MR122)
							{
								num21 >>= 1;
							}
							array6[num3 + j] = (int)(num21 + 32768L >> 16);
						}
					}
					if (num9 == 0)
					{
						for (j = 0; j < 8; j++)
						{
							decoder_amrState_0.ltpGainHistory[decoder_amrState_0.ltpGainHistoryOffset + j] = decoder_amrState_0.ltpGainHistory[decoder_amrState_0.ltpGainHistoryOffset + j + 1];
						}
						decoder_amrState_0.ltpGainHistory[decoder_amrState_0.ltpGainHistoryOffset + 8] = num7;
					}
					if ((decoder_amrState_0.prev_bf != 0 || num9 != 0) & decoder_amrState_0.inBackgroundNoise != 0 & (mode == Mode.MR475 || mode == Mode.MR515 || mode == Mode.MR59))
					{
						if (num7 > 12288)
						{
							num7 = (num7 - 12288 >> 1) + 12288;
						}
						if (num7 > 14745)
						{
							num7 = 14745;
						}
					}
					GloabFunc_Dec.Int_lsf(array3, decoder_amrState_0.lsfState.past_lsf_q, i, array4);
					int cbGain = GloabFunc_Dec.Cb_gain_average(decoder_amrState_0.Cb_gain_averState, mode, num6, array4, decoder_amrState_0.lsp_avg_st.lsp_meanSave, num9, decoder_amrState_0.prev_bf, num10, decoder_amrState_0.prev_pdf, decoder_amrState_0.inBackgroundNoise, decoder_amrState_0.voicedHangover);
					if (mode > Mode.MR67 & mode != Mode.MR102)
					{
						cbGain = num6;
					}
					int num22;
					short num23;
					if (mode <= Mode.MR102)
					{
						num22 = num7;
						num23 = 1;
					}
					else
					{
						num22 = num7 >> 1;
						num23 = 2;
					}
					GloabFunc.memcpyInt(array7, num4, decoder_amrState_0.int_0, decoder_amrState_0.excOffset, 40);
					for (j = 0; j < 40; j++)
					{
						num5 = decoder_amrState_0.int_0[decoder_amrState_0.excOffset + j] * num22 + array5[num2 + j] * num6;
						num21 = (long)((long)num5 << (int)num23);
						if (((num21 >> 1 ^ num21) & 1073741824L) != 0L)
						{
							if ((((long)num5 ^ num21) & (long)((ulong)-2147483648)) != 0L)
							{
								num21 = (((int)((long)num5 & (long)((ulong)-2147483648)) != 0) ? -1073741824L : 1073725439L);
							}
							else
							{
								num21 = (((num21 & (long)((ulong)-2147483648)) != 0L) ? -1073741824L : 1073725439L);
							}
						}
						decoder_amrState_0.int_0[decoder_amrState_0.excOffset + j] = (int)(num21 + 16384L >> 15);
					}
					decoder_amrState_0.ph_disp_st.lockFull = 0;
					if ((mode == Mode.MR475 || mode == Mode.MR515 || mode == Mode.MR59) & decoder_amrState_0.voicedHangover > 3 & decoder_amrState_0.inBackgroundNoise != 0 & num9 != 0)
					{
						decoder_amrState_0.ph_disp_st.lockFull = 1;
					}
					GloabFunc_Dec.ph_disp(decoder_amrState_0.ph_disp_st, mode, array7, num4, cbGain, num7, array5, num2, num22, (int)num23);
					num21 = 0L;
					for (j = 0; j < 40; j++)
					{
						num21 += (long)(array7[num4 + j] * array7[num4 + j]);
					}
					int num24;
					if (num21 > 1073741823L)
					{
						num24 = 11584;
					}
					else
					{
						num21 = (long)GloabFunc_Dec.sqrt_l_exp((int)num21, ref num5);
						num21 >>= (num5 >> 1) + 15;
						num24 = (int)(num21 >> 2);
					}
					if ((mode == Mode.MR475 || mode == Mode.MR515 || mode == Mode.MR59) & decoder_amrState_0.voicedHangover > 5 & decoder_amrState_0.inBackgroundNoise != 0 & decoder_amrState_0.state < 4 & ((num10 != 0 & decoder_amrState_0.prev_pdf != 0) || num9 != 0 || decoder_amrState_0.prev_bf != 0))
					{
						short carefulFlag = 0;
						if (num10 != 0 & num9 == 0)
						{
							carefulFlag = 1;
						}
						GloabFunc_Dec.Ex_ctrl(array7, num24, decoder_amrState_0.excEnergyHist, decoder_amrState_0.voicedHangover, decoder_amrState_0.prev_bf, carefulFlag);
					}
					if (!(decoder_amrState_0.inBackgroundNoise != 0 & (num9 != 0 || decoder_amrState_0.prev_bf != 0) & decoder_amrState_0.state < 4))
					{
						for (j = 0; j < 8; j++)
						{
							decoder_amrState_0.excEnergyHist[decoder_amrState_0.excEnergyHistOffset + j] = decoder_amrState_0.excEnergyHist[decoder_amrState_0.excEnergyHistOffset + j + 1];
						}
						decoder_amrState_0.excEnergyHist[decoder_amrState_0.excEnergyHistOffset + 8] = num24;
					}
					int num25;
					if (num20 > 16384)
					{
						for (j = 0; j < 40; j++)
						{
							array6[num3 + j] = array6[num3 + j] + array7[num4 + j];
							if (Math.Abs(array6[num3 + j]) > 32767)
							{
								array6[num3 + j] = ((((long)array6[num3 + j] & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
							}
						}
						GloabFunc_Dec.agc2(array7, num4, array6, num3);
						num25 = GloabFunc_Dec.Syn_filt(A_t, num11, array6, num3, synth, synthOffset + i, 40, decoder_amrState_0.mem_syn, 0, 0);
					}
					else
					{
						num25 = GloabFunc_Dec.Syn_filt(A_t, num11, array7, num4, synth, synthOffset + i, 40, decoder_amrState_0.mem_syn, 0, 0);
					}
					if (num25 != 0)
					{
						for (j = 0; j < 194; j++)
						{
							decoder_amrState_0.old_exc[decoder_amrState_0.old_excOffset + j] = decoder_amrState_0.old_exc[decoder_amrState_0.old_excOffset + j] >> 2;
						}
						for (j = 0; j < 40; j++)
						{
							array7[num4 + j] = array7[num4 + j] >> 2;
						}
						GloabFunc_Dec.Syn_filt_overflow(A_t, num11, array7, num4, synth, synthOffset + i, 40, decoder_amrState_0.mem_syn, 0, 1);
					}
					else
					{
						GloabFunc.memcpyInt(decoder_amrState_0.mem_syn, 0, synth, synthOffset + i + 30, 10);
					}
					GloabFunc.memcpyInt(decoder_amrState_0.old_exc, decoder_amrState_0.old_excOffset, decoder_amrState_0.old_exc, decoder_amrState_0.old_excOffset + 40, 154);
					num11 += 11;
					decoder_amrState_0.old_T0 = num8;
					i += 40;
					continue;
					IL_4DB:
					num15 = (int)parm[parmOffset];
					parmOffset++;
					j = (int)parm[parmOffset];
					parmOffset++;
					GloabFunc_Dec.decode_2i40_9bits(num13, j, num15, array5);
					num20 = decoder_amrState_0.sharp << 1;
					goto IL_506;
				}
				decoder_amrState_0.inBackgroundNoise = (int)GloabFunc_Dec.Bgn_scd(decoder_amrState_0.background_state, decoder_amrState_0.ltpGainHistory, synth, synthOffset, ref decoder_amrState_0.voicedHangover);
				GloabFunc_Dec.dtx_dec_activity_update(decoder_amrState_0.dtxDecoderState, decoder_amrState_0.lsfState.past_lsf_q, synth, synthOffset);
				decoder_amrState_0.prev_bf = num9;
				decoder_amrState_0.prev_pdf = num10;
				GloabFunc_Dec.lsp_avg(decoder_amrState_0.lsp_avg_st, decoder_amrState_0.lsfState.past_lsf_q, 0);
			}
			decoder_amrState_0.dtxDecoderState.dtxGlobalState = dTXStateType;
		}
		private static void Residu40(int[] int_0, int aOffset, int[] int_1, int xOffset, int[] int_2, int yOffset)
		{
			for (int i = 0; i < 40; i++)
			{
				int num = int_0[aOffset] * int_1[xOffset + i] + int_0[aOffset + 1] * int_1[xOffset + i - 1] + int_0[aOffset + 2] * int_1[xOffset + i - 2] + int_0[aOffset + 3] * int_1[xOffset + i - 3];
				num += int_0[aOffset + 4] * int_1[xOffset + i - 4] + int_0[aOffset + 5] * int_1[xOffset + i - 5] + int_0[aOffset + 6] * int_1[xOffset + i - 6] + int_0[aOffset + 7] * int_1[xOffset + i - 7];
				num += int_0[aOffset + 8] * int_1[xOffset + i - 8] + int_0[aOffset + 9] * int_1[xOffset + i - 9] + int_0[aOffset + 10] * int_1[xOffset + i - 10];
				int_2[yOffset + i] = num + 2048 >> 12;
				if (Math.Abs(int_2[yOffset + i]) > 32767)
				{
					for (i = 0; i < 40; i++)
					{
						num = int_0[aOffset] * int_1[xOffset + i];
						for (int j = 1; j <= 10; j++)
						{
							num += int_0[aOffset + j] * int_1[xOffset + i - j];
							if (num > 1073741823)
							{
								num = 1073741823;
							}
							else
							{
								if (num < -1073741824)
								{
									num = -1073741824;
								}
							}
						}
						int_2[yOffset + i] = num + 2048 >> 12;
						if (Math.Abs(int_2[yOffset + i]) > 32767)
						{
							int_2[yOffset + i] = ((((long)int_2[yOffset + i] & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
						}
					}
					return;
				}
			}
		}
		private static void smethod_0(GloabFunc_Dec.agcState agcState_0, int[] sig_in, int sig_inOffset, int[] sig_out, int sig_outOffset, int agc_fac)
		{
			int num = GloabFunc_Dec.energy_new(sig_out, sig_outOffset);
			if (num == 0)
			{
				agcState_0.past_gain = 0;
				return;
			}
			int num2 = 0;
			int i = num;
			while ((i & 1073741824) == 0)
			{
				num2++;
				i <<= 1;
			}
			num2--;
			if (((long)num2 & (long)((ulong)-2147483648)) != 0L)
			{
				num >>= 1;
			}
			else
			{
				num <<= num2;
			}
			int num3 = (int)((long)num + 32768L >> 16);
			num = GloabFunc_Dec.energy_new(sig_in, sig_inOffset);
			int num4;
			if (num == 0)
			{
				num4 = 0;
			}
			else
			{
				i = 0;
				while ((num & 1073741824) == 0)
				{
					i++;
					num <<= 1;
				}
				num = (int)((long)num + 32768L);
				int num5;
				if (num >= 0)
				{
					num5 = num >> 16;
				}
				else
				{
					num5 = 32767;
				}
				num2 -= i;
				num = (num3 << 15) / num5;
				num2 = 7 - num2;
				if (num2 > 0)
				{
					if (num2 > 31)
					{
						if (num != 0)
						{
							num = 2147483647;
						}
					}
					else
					{
						num <<= num2;
					}
				}
				else
				{
					num >>= -num2;
				}
				if (num < 0)
				{
					num = 2147483647;
				}
				num = GloabFunc_Dec.Inv_sqrt(num);
				i = (int)((long)((long)num << 9) + 32768L >> 16);
				if (((long)i & (long)((ulong)-32768)) != 0L)
				{
					i = 32767;
				}
				num4 = i * (32767 - agc_fac) >> 15;
			}
			int num6 = agcState_0.past_gain;
			for (i = 0; i < 40; i++)
			{
				num6 = num6 * agc_fac >> 15;
				num6 += num4;
				sig_out[sig_outOffset + i] = sig_out[sig_outOffset + i] * num6 >> 12;
				if (Math.Abs(sig_out[sig_outOffset + i]) > 32767)
				{
					sig_out[sig_outOffset + i] = (((sig_out[sig_outOffset + i] & 134217728) != 0) ? -32768 : 32767);
				}
			}
			agcState_0.past_gain = num6;
		}
		private static void Post_Filter(GloabFunc_Dec.Post_FilterState post_FilterState_0, Mode mode, int[] int_0, int synOffset, int[] Az_4, int Az_4Offset)
		{
			int[] array = new int[22];
			int num = 0;
			int[] array2 = new int[11];
			int num2 = 0;
			int[] array3 = new int[11];
			int num3 = 0;
			int[] synth_buf = post_FilterState_0.synth_buf;
			int num4 = 10;
			int[] array4 = DefineConstants_Dec.gamma3;
			int num5 = 0;
			int[] array5 = DefineConstants_Dec.gamma4_gamma3_MR122;
			int num6 = 0;
			GloabFunc.memcpyInt(synth_buf, 10, int_0, synOffset, 160);
			int num7 = Az_4Offset;
			if (mode == Mode.MR122 || mode == Mode.MR102)
			{
				array4 = DefineConstants_Dec.gamma4_gamma3_MR122;
				num5 = 0;
				array5 = DefineConstants_Dec.gamma4_MR122;
				num6 = 0;
			}
			for (int i = 0; i < 160; i += 40)
			{
				array2[num2] = Az_4[num7];
				array3[num3] = Az_4[num7];
				for (int j = 1; j <= 10; j++)
				{
					array2[num2 + j] = Az_4[num7 + j] * array4[num5 + j - 1] + 16384 >> 15;
					array3[num3 + j] = Az_4[num7 + j] * array5[num6 + j - 1] + 16384 >> 15;
				}
				GloabFunc_Dec.Residu40(array2, num2, synth_buf, num4 + i, post_FilterState_0.res2, 0);
				GloabFunc.memcpyInt(array, num, array2, num2, 11);
				GloabFunc.memsetInt(array, num + 10 + 1, 0, 44);
				GloabFunc_Dec.Syn_filt(array3, num3, array, num, array, num, 22, array, num + 10 + 1, 0);
				int num8 = 16777216 + array[num + 1] * array[num + 1];
				for (int j = 2; j < 22; j++)
				{
					num8 += array[num + j] * array[num + j];
					if (num8 > 1073709056)
					{
						break;
					}
				}
				int num9 = num8 >> 15;
				if (((long)num9 & (long)((ulong)-32768)) != 0L)
				{
					num9 = 32767;
				}
				num8 = array[num] * array[num + 1];
				for (int j = 1; j < 21; j++)
				{
					num8 += array[num + j] * array[num + j + 1];
					if (Math.Abs(num8) > 1073741823)
					{
						num8 = 1073741823;
					}
				}
				long num10 = (long)(num8 >> 15);
				if (num10 <= 0L)
				{
					num10 = 0L;
				}
				else
				{
					num8 = (int)(num10 * 26214L);
					num10 = ((long)num8 & (long)((ulong)-32768)) / (long)num9;
				}
				int[] res = post_FilterState_0.res2;
				int num11 = 39;
				int[] array6 = res;
				int num12 = 39 - 1;
				num8 = res[39];
				do
				{
					res[num11] = (int)((long)res[num11] - (num10 * (long)array6[num12--] >> 15));
					if (Math.Abs(res[num11]) > 32767)
					{
						res[num11] = ((((long)res[num11] & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
					}
					num11--;
					res[num11] = (int)((long)res[num11] - (num10 * (long)array6[num12--] >> 15));
					if (Math.Abs(res[num11]) > 32767)
					{
						res[num11] = ((((long)res[num11] & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
					}
					num11--;
					res[num11] = (int)((long)res[num11] - (num10 * (long)array6[num12--] >> 15));
					if (Math.Abs(res[num11]) > 32767)
					{
						res[num11] = ((((long)res[num11] & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
					}
					num11--;
				}
				while (num11 > 0);
				res[num11] = (int)((long)res[num11] - (num10 * (long)post_FilterState_0.preemph_state_mem_pre >> 15));
				if (Math.Abs(res[num11]) > 32767)
				{
					res[num11] = ((((long)res[num11] & (long)((ulong)-2147483648)) != 0L) ? -32768 : 32767);
				}
				post_FilterState_0.preemph_state_mem_pre = num8;
				int num13 = GloabFunc_Dec.Syn_filt(array3, num3, post_FilterState_0.res2, 0, int_0, synOffset + i, 40, post_FilterState_0.mem_syn_pst, 0, 0);
				if (num13 != 0)
				{
					GloabFunc_Dec.Syn_filt_overflow(array3, num3, post_FilterState_0.res2, 0, int_0, synOffset + i, 40, post_FilterState_0.mem_syn_pst, 0, 1);
				}
				else
				{
					GloabFunc.memcpyInt(post_FilterState_0.mem_syn_pst, 0, int_0, synOffset + i + 30, 10);
				}
				GloabFunc_Dec.smethod_0(post_FilterState_0.agc_state, synth_buf, num4 + i, int_0, synOffset + i, 29491);
				num7 += 11;
			}
			GloabFunc.memcpyInt(synth_buf, num4 - 10, synth_buf, num4 + 160 - 10, 10);
		}
		private static void Post_Process(ref GloabFunc_Dec.Post_ProcessState post_ProcessState_0, int[] signal, int signalOffset)
		{
			int num = 0;
			int num2 = 1073741824;
			do
			{
				int int_ = post_ProcessState_0.int_1;
				post_ProcessState_0.int_1 = post_ProcessState_0.int_0;
				post_ProcessState_0.int_0 = signal[num + signalOffset];
				long num3 = (long)(post_ProcessState_0.y1_hi * 15836) + (((long)(post_ProcessState_0.y1_lo * 15836) & (long)((ulong)-32768)) >> 15);
				num3 += (long)(post_ProcessState_0.y2_hi * -7667 + ((int)((long)(post_ProcessState_0.y2_lo * -7667) & (long)((ulong)-32768)) >> 15));
				num3 += (long)(post_ProcessState_0.int_0 * 7699);
				num3 += (long)(post_ProcessState_0.int_1 * -15398);
				if (((num3 >> 1 ^ num3) & (long)num2) != 0L)
				{
					num3 = (((num3 & (long)((ulong)-2147483648)) != 0L) ? -1073741824L : 1073741823L);
				}
				num3 += (long)(int_ * 7699);
				if (((num3 >> 1 ^ num3) & (long)num2) != 0L)
				{
					num3 = (((num3 & (long)((ulong)-2147483648)) != 0L) ? -1073741824L : 1073741823L);
				}
				num3 <<= 1;
				if (((num3 >> 1 ^ num3) & (long)num2) != 0L)
				{
					num3 = (((num3 & (long)((ulong)-2147483648)) != 0L) ? -1073741824L : 1073741823L);
				}
				num3 <<= 1;
				if (((num3 >> 1 ^ num3) & (long)num2) != 0L)
				{
					num3 = (((num3 & (long)((ulong)-2147483648)) != 0L) ? -1073741824L : 1073741823L);
				}
				if (Math.Abs(num3) < 536862720L)
				{
					signal[num + signalOffset] = (int)(num3 + 8192L >> 14);
					num++;
				}
				else
				{
					if (num3 > 0L)
					{
						signal[num + signalOffset] = 32767;
						num++;
					}
					else
					{
						signal[num + signalOffset] = -32768;
						num++;
					}
				}
				post_ProcessState_0.y2_hi = post_ProcessState_0.y1_hi;
				post_ProcessState_0.y2_lo = post_ProcessState_0.y1_lo;
				post_ProcessState_0.y1_hi = (int)(num3 >> 15);
				post_ProcessState_0.y1_lo = (int)((num3 << 1) - (long)((long)post_ProcessState_0.y1_hi << 16) >> 1);
			}
			while (num < 160);
		}
		public static void Speech_Decode_Frame(object object_0, Mode mode, short[] parm, int parmOffset, RXFrameType frame_type, short[] synth, int synthOffset)
		{
			int[] array = new int[44];
			int[] array2 = new int[160];
			int num = 0;
			GloabFunc_Dec.Decoder_amr(((GloabFunc_Dec.Speech_Decode_FrameState)object_0).decoder_amrState, mode, parm, parmOffset, frame_type, array2, 0, array, 0);
			GloabFunc_Dec.Post_Filter(((GloabFunc_Dec.Speech_Decode_FrameState)object_0).post_state, mode, array2, 0, array, 0);
			GloabFunc_Dec.Post_Process(ref ((GloabFunc_Dec.Speech_Decode_FrameState)object_0).postHP_state, array2, 0);
			for (int i = 0; i < 160; i++)
			{
				synth[i + synthOffset] = (short)(array2[num + i] & 65528);
			}
		}
		private static void Decoder_amr_exit(ref GloabFunc_Dec.Decoder_amrState state)
		{
			if (state == null)
			{
				return;
			}
			state.lsfState = null;
			state.ec_gain_p_st = null;
			state.ec_gain_c_st = null;
			state.pred_state = null;
			state.background_state = null;
			state.ph_disp_st = null;
			state.Cb_gain_averState = null;
			state.lsp_avg_st = null;
			state.dtxDecoderState = null;
			state = null;
		}
		private static void Post_Filter_exit(ref GloabFunc_Dec.Post_FilterState state)
		{
			if (state == null)
			{
				return;
			}
			state.agc_state = null;
			state = null;
		}
		private static int Post_Process_reset(ref GloabFunc_Dec.Post_ProcessState state)
		{
			if (state == null)
			{
				return -1;
			}
			state.y2_hi = 0;
			state.y2_lo = 0;
			state.y1_hi = 0;
			state.y1_lo = 0;
			state.int_0 = 0;
			state.int_1 = 0;
			return 0;
		}
		private static void Post_Process_exit(ref GloabFunc_Dec.Post_ProcessState state)
		{
			if (state == null)
			{
				return;
			}
			state = null;
		}
		private static int Decoder_amr_init(ref GloabFunc_Dec.Decoder_amrState state)
		{
			state = null;
			GloabFunc_Dec.Decoder_amrState decoder_amrState = new GloabFunc_Dec.Decoder_amrState();
			decoder_amrState.lsfState = new GloabFunc_Dec.D_plsfState();
			decoder_amrState.ec_gain_p_st = new GloabFunc_Dec.ec_gain_pitchState();
			decoder_amrState.ec_gain_c_st = new GloabFunc_Dec.ec_gain_codeState();
			decoder_amrState.pred_state = new GloabFunc_Dec.gc_predState();
			decoder_amrState.Cb_gain_averState = new GloabFunc_Dec.Cb_gain_averageState();
			GloabFunc.memsetInt(decoder_amrState.Cb_gain_averState.cbGainHistory, 0, 0, 28);
			decoder_amrState.Cb_gain_averState.hangVar = 0;
			decoder_amrState.Cb_gain_averState.hangCount = 0;
			decoder_amrState.lsp_avg_st = new GloabFunc_Dec.lsp_avgState();
			decoder_amrState.background_state = new GloabFunc_Dec.Bgn_scdState();
			decoder_amrState.ph_disp_st = new GloabFunc_Dec.ph_dispState();
			decoder_amrState.dtxDecoderState = new GloabFunc_Dec.dtx_decState();
			GloabFunc_Dec.Decoder_amr_reset(decoder_amrState, Mode.MR475);
			state = decoder_amrState;
			return 0;
		}
		private static int Post_Filter_reset(GloabFunc_Dec.Post_FilterState state)
		{
			if (state == null)
			{
				return -1;
			}
			state.preemph_state_mem_pre = 0;
			state.agc_state.past_gain = 4096;
			GloabFunc.memsetInt(state.mem_syn_pst, 0, 0, 40);
			GloabFunc.memsetInt(state.res2, 0, 0, 160);
			GloabFunc.memsetInt(state.synth_buf, 0, 0, 680);
			return 0;
		}
		private static int Post_Filter_init(ref GloabFunc_Dec.Post_FilterState state)
		{
			state = null;
			GloabFunc_Dec.Post_FilterState post_FilterState = new GloabFunc_Dec.Post_FilterState();
			post_FilterState.agc_state = null;
			if ((post_FilterState.agc_state = new GloabFunc_Dec.agcState()) == null)
			{
				return -1;
			}
			GloabFunc_Dec.Post_Filter_reset(post_FilterState);
			state = post_FilterState;
			return 0;
		}
		private static int Post_Process_init(ref GloabFunc_Dec.Post_ProcessState state)
		{
			state = null;
			GloabFunc_Dec.Post_ProcessState post_ProcessState = new GloabFunc_Dec.Post_ProcessState();
			GloabFunc_Dec.Post_Process_reset(ref post_ProcessState);
			state = post_ProcessState;
			return 0;
		}
		public static void Speech_Decode_Frame_exit(object object_0)
		{
			if ((GloabFunc_Dec.Speech_Decode_FrameState)object_0 == null)
			{
				return;
			}
			GloabFunc_Dec.Decoder_amr_exit(ref ((GloabFunc_Dec.Speech_Decode_FrameState)object_0).decoder_amrState);
			GloabFunc_Dec.Post_Filter_exit(ref ((GloabFunc_Dec.Speech_Decode_FrameState)object_0).post_state);
			GloabFunc_Dec.Post_Process_exit(ref ((GloabFunc_Dec.Speech_Decode_FrameState)object_0).postHP_state);
			object_0 = null;
		}
		public static int Speech_Decode_Frame_reset(object object_0)
		{
			if (object_0 == null)
			{
				return -1;
			}
			GloabFunc_Dec.Speech_Decode_FrameState speech_Decode_FrameState = (GloabFunc_Dec.Speech_Decode_FrameState)object_0;
			GloabFunc_Dec.Decoder_amr_reset(speech_Decode_FrameState.decoder_amrState, Mode.MR475);
			GloabFunc_Dec.Post_Filter_reset(speech_Decode_FrameState.post_state);
			GloabFunc_Dec.Post_Process_reset(ref speech_Decode_FrameState.postHP_state);
			return 0;
		}
		public static object Speech_Decode_Frame_init()
		{
			GloabFunc_Dec.Speech_Decode_FrameState speech_Decode_FrameState = new GloabFunc_Dec.Speech_Decode_FrameState();
			if (speech_Decode_FrameState == null)
			{
				return null;
			}
			speech_Decode_FrameState.decoder_amrState = null;
			speech_Decode_FrameState.post_state = null;
			speech_Decode_FrameState.postHP_state = null;
			if (GloabFunc_Dec.Decoder_amr_init(ref speech_Decode_FrameState.decoder_amrState) == 0 && GloabFunc_Dec.Post_Filter_init(ref speech_Decode_FrameState.post_state) == 0 && GloabFunc_Dec.Post_Process_init(ref speech_Decode_FrameState.postHP_state) == 0)
			{
				return speech_Decode_FrameState;
			}
			GloabFunc_Dec.Speech_Decode_Frame_exit(speech_Decode_FrameState);
			return null;
		}
	}
}
